Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fields that do not exist

Status
Not open for further replies.

jeroldqc

Programmer
Jun 18, 2001
6
0
0
PH
Hi guys!

How do I create a query/select wherein I only need field(s) from Table 2 that do not exist in Table1?

Table1
id field
-- -----
1 A
2 B
3 C


Table2
id field
-- -----
1 A
4 D
5 E

I need this result:
id field
-- -----
4 D
5 E
 
Try:
[tt]
SELECT * FROM Table2 WHERE NOT EXISTS (SELECT * FROM Table1 WHERE Table1.id=Table2.id;);
[/TT]
 
You may try this:
SELECT T2.* FROM Table2 T2 LEFT JOIN Table1 T1
ON T2.Field = T1.Field
WHERE T1.Field IS NULL;

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top