SELECT / JOIN all unmatched records

Thesize
04-20-2004, 06:08 PM
I am trying to write a select statement that will join two tables and return the records for both tables which have no match in the other table.

Please help.

Thanks,

Jeff

couch612
04-20-2004, 06:37 PM
you can do this in two select queries. Query 1 will return records in Table1 that do not exist in Table 2:

1. SELECT Table1.*
FROM Table1 LEFT JOIN Table2 ON Table1.Key = Table2.Key
WHERE Table2.Key IS NULL;

Query 2 will return records in Table2 that are not in Table1:

2. SELECT Table2.*
FROM Table2 LEFT JOIN Table1 ON Table2.Key = Table1.Key
WHERE Table1.Key IS NULL;

MKoslof
04-20-2004, 08:30 PM
You can probably do this one query. With a Left JOIN or Right JOIN you can get all records from one table and specific records from another table. If you want all records from both tables, but only unique fields and values, you could do a UNION.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum