Not Exists Query Not Working

snipered

Registered User.
Local time
Today, 13:04
Joined
Jan 19, 2005
Messages
15
Hi, i have a simple query but for some reason it's not working.

Let me get to the point.
2 tables - table1(id,txtfield1) table2(userid, idfield)
idfield contains id so foreign key (although hasnt been set up as that yet)

Aim: select all fields from table1 where table2 doesn't contain them.

e.g if table 1 had, 5 rows containing:
1 - test
2 - test2
3 - test3
4 - test4
5 - test6

and table 2 had:
1 - 4
2 - 5

Then when the query ran, it would only pick up 1 - test, 2 - test2, 3 - test3.

Any ideas. I have tried but with no luck:

Code:
SELECT [ID], [txtfield1] FROM table1 WHERE NOT EXISTS (SELECT [idfield] FROM table2)
 
Let Wizard to make this query for you.
Find Unmetched Query Wizard
 
Code:
SELECT [ID], [txtfield1] 
FROM table1 
LEFT JOIN table2
ON [ID] = [idfield]
WHERE idfield is NULL

Which is basically what the unmatched query wizard will do.
 

Users who are viewing this thread

Back
Top Bottom