| ||||||
| 5/25 |
| 2004/4/9 [Computer/SW/Database] UID:13107 Activity:nil |
4/8 In SQL, say I have two tables, one references to another. What is the
query that will list all the entries in the first table that doesn't
occur in the second table? I'd like to do "SELECT a.id FROM
a,b WHERE a.id!=b.id". However, this doesn't quite work. Thanks.
\_ The following works in PostgreSQL; I don't know if the IS NULL
syntax is part of SQL or an extension. Note that, in Postgres,
replacing 'IS NULL' with '= NULL' doesn't work.
SELECT a.id FROM a LEFT OUTER JOIN b ON a.id=b.id WHERE b.id IS NULL
There may well be a more efficient way of doing this, but this
one works. -gm
\_ SELECT id FROM first_table a WHERE NOT EXISTS
(SELECT * FROM second_table b WHERE b.id = a.id) |
| 5/25 |
|