Before this I'd never beefore needed to use the "LEFT JOIN" command, and unfortunately it's giving me some problems.
I have three tables setup as follows (note they are test tables for a prototype of a larger project):
user_table:
| UserID | Username | Password|
| 1 | julian | abcdef |
| 2 | test | test |
file_table:
| FileID | UserID | File |
| 1 | 1 | file1.txt|
| 2 | 1 | file2.txt |
| 3 | 2 | file2.txt |
list_table:
| ListID | FileName |
| 1 | file1.txt |
| 2 | file2.txt |
| 3 | file3.txt |
I want to run a query that will display all rows of "FileName" on the second column, and "FileAccess" on the second column IF FileAccess is equal to FileName and UserID in TableB is equal to a variable which is given a value in a previous part of my program. (For simplicity sake it has been given the value two.
This is my query:
Expand|Select|Wrap|Line Numbers
- sql = "SELECT file_list.FileName, file_table.FileAccess FROM file_list "
- sql = sql & "LEFT JOIN file_table ON file_list.FileName = file_table.FileAccess "
- sql = sql & "WHERE file_table.UserID = 2"
FileName | FileAccess
file2.txt | file2.txt
This is what I WANT it to return:
FileName | FileAccess
file1.txt |
file2.txt | file2.txt
I've tried all types of variations of the query and even tried to make it a right join all without success. Any help with the query will be greatly appreciated.