Re: Non Matching Records in Two Tables

From: Frank Bax <fbax(at)sympatico(dot)ca>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Non Matching Records in Two Tables
Date: 2006-02-08 21:27:04
Message-ID: 5.2.1.1.0.20060208162115.023e7ec0@pop6.sympatico.ca
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 04:10 PM 2/8/06, Ken Hill wrote:
>I need some help with a bit of SQL. I have two tables. I want to find
>records in one table that don't match records in another table based on a
>common column in the two tables. Both tables have a column named 'key100'.
>I was trying something like:
>
>SELECT count(*)
>FROM table1, table2
>WHERE (table1.key100 != table2.key100);
>
>But the query is very slow and I finally just cancel it. Any help is very
>much appreciated.

vacuum analyse table1;

vacuum analyse table2;

select count(*) from table1 full outer join table2 on
table1.key100=table2.key100 where table1.key100 is null or table2.key100 is
null;

If this is also slow, post output of "EXPLAIN ANALYSE SELECT ...."

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Markus Schaber 2006-02-08 21:31:31 Re: Non Matching Records in Two Tables
Previous Message Ken Hill 2006-02-08 21:10:23 Non Matching Records in Two Tables