This is a discussion on Opposite of "not in" within the pgsql Sql forums, part of the PostgreSQL category; --> Hello, A common query that I have is to see if a member of a table is in a ...
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hello, A common query that I have is to see if a member of a table is in a list. Simple enough: SELECT * FROM drivers WHERE driver_id IN (123, 456, 789) Or not in the list: SELECT * FROM drivers WHERE driver_id NOT IN (123, 456, 789) However sometimes I want to know which members of the list are not in the table. My pseudo SQL looks like this: SELECT * FROM (123, 456, 789) WHERE NOT IN drivers What's the easiest way to write this in SQL (using Postgres 7.3)? Thanks, CF |
| ||||
| ChronoFish wrote: > However sometimes I want to know which members of the list are not in > the table. My pseudo SQL looks like this: > > SELECT * FROM (123, 456, 789) WHERE NOT IN drivers > > What's the easiest way to write this in SQL (using Postgres 7.3)? SELECT * FROM whatever WHERE driver_id NOT IN (SELECT driver_id FROM drivers); -- Lew |