Search Postgresql Archives

Incorrect results with NOT IN

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux