Re: select * from users where user_id NOT in (select

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com>
Cc: Alexander Farber <alexander(dot)farber(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org, Bruce Momjian <bruce(at)momjian(dot)us>
Subject: Re: select * from users where user_id NOT in (select
Date: 2006-08-18 00:40:38
Message-ID: 1046.1155861638@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Stephan Szabo <sszabo(at)megazone(dot)bigpanda(dot)com> writes:
> On Thu, 17 Aug 2006, Alexander Farber wrote:
>> But the negative one returns nothing:
>>
>> phpbb=> select user_id, username from phpbb_users
>> phpbb-> where user_id not in (select ban_userid from phpbb_banlist);
>> user_id | username
>> ---------+----------
>> (0 rows)

> Sadly, these two look like they would give you all the users rows, but
> they don't because of the NULL ban_userid. When the subselect returns
> NULL for at least one row, you fall into this sort of case.

Seems like the NULLs-in-NOT-IN thing ought to be in our FAQ list.
It certainly bites newbies often enough :-(

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2006-08-18 00:47:10 Re: count and limit
Previous Message Jeff Davis 2006-08-18 00:35:11 Re: Dynamic Partial Index