Unix Technical Forum

Opposite of "not in"

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 ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 06:00 PM
ChronoFish
 
Posts: n/a
Default Opposite of "not in"

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 06:01 PM
Lew
 
Posts: n/a
Default Re: Opposite of "not in"

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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 10:11 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com