Incorrect results with NOT IN

From: Nick <nboutelier(at)hotmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Incorrect results with NOT IN
Date: 2008-08-15 02:06:26
Message-ID: 45648a47-38d3-4bad-8471-4b6c264bc78e@z6g2000pre.googlegroups.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

I have a weird scenario on a table when I run this query...

table1 has 1500 rows
table2 has 1200 rows
table2.id is a foreign key of table1.id

SELECT COUNT(*) FROM table1
WHERE id NOT IN (
SELECT id FROM table2
);

however, using NOT EXISTS works

SELECT COUNT(*) FROM table1
WHERE NOT EXISTS (
SELECT id FROM table2 WHERE table1.id = table2.id
);

Can you not use NOT IN over a specific number of values??

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Sullivan 2008-08-15 03:02:49 Re: [Q] DNS(bind) ER model
Previous Message Craig Ringer 2008-08-15 01:58:57 Re: Custom sort