Re: Finding missing records

Поиск
Список
Период
Сортировка
От John D. Burger
Тема Re: Finding missing records
Дата
Msg-id 76d00d2736badf0d1593d30d9666d7fb@mitre.org
обсуждение исходный текст
Ответ на Finding missing records  ("Stefano B." <stefano.bonnin@comai.to>)
Ответы Re: Finding missing records  ("John D. Burger" <john@mitre.org>)
Список pgsql-general
On Jan 27, 2006, at 08:59, Stefano B. wrote:

> select f1,f2,f3,f4 from table1 where (f1,f2,f3,f4) NOT IN (select
> f1,f2,f3,f4 from table2)
>  
> but it seems not work (as I want). It returns me no records. If I use
> the IN clause it returns me all 10000 table1 records.

The standard way to do this is:

   select f1,f2,f3,f4 from table1
   except
   select f1,f2,f3,f4 from table2;

Note that IN and EXCEPT are essentially set operators - if you have
duplicates in either table, you might not get what you expect.  Your
last comment above seems to indicate that this is indeed the case.

If what you want is the =bag= difference of the two tables, you'll have
to do something more complicated.  Possible solutions might involve
counting duplicates in both tables with a COUNT(*) and GROUP BY, and
then joining on the four columns and subtracting the counts.

- John D. Burger
   MITRE

В списке pgsql-general по дате отправления:

Предыдущее
От: Pandurangan R S
Дата:
Сообщение: Re: Finding missing records
Следующее
От: Richard Huxton
Дата:
Сообщение: Re: PG_RESTORE and database size