Another mysteriously unknown RDBMS. Your syntax is great for PostgreSQL. Other query styles may be faster (especially the NOT EXISTS or LEFT JOIN option), but your query is completely correct.
Remember traps with NOT IN , although when using any NULL values:
- Find records in which the connection does not exist
Option with LEFT JOIN:
SELECT * FROM friend f LEFT JOIN likes l USING (id1, id2) WHERE l.id1 IS NULL;
See @ Michał answer for the NOT EXISTS option.
A more detailed assessment of the four main options:
- Select rows not in another table.
Erwin Brandstetter Nov 07 '11 at 7:18 2011-11-07 07:18
source share