X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id 5D84C9DCABB for ; Wed, 8 Feb 2006 17:27:23 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 57830-04 for ; Wed, 8 Feb 2006 17:27:23 -0400 (AST) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from tomts40-srv.bellnexxia.net (tomts40.bellnexxia.net [209.226.175.97]) by postgresql.org (Postfix) with ESMTP id 2DE289DC815 for ; Wed, 8 Feb 2006 17:27:19 -0400 (AST) Received: from acer.sympatico.ca ([70.50.209.247]) by tomts40-srv.bellnexxia.net (InterMail vM.5.01.06.13 201-253-122-130-113-20050324) with ESMTP id <20060208212720.NJFA5216.tomts40-srv.bellnexxia.net@acer.sympatico.ca> for ; Wed, 8 Feb 2006 16:27:20 -0500 Message-Id: <5.2.1.1.0.20060208162115.023e7ec0@pop6.sympatico.ca> X-Sender: b1wudu74@pop6.sympatico.ca X-Mailer: QUALCOMM Windows Eudora Version 5.2.1 Date: Wed, 08 Feb 2006 16:27:04 -0500 To: pgsql-sql@postgresql.org From: Frank Bax Subject: Re: Non Matching Records in Two Tables In-Reply-To: <1139433024.2044.48.camel@localhost.localdomain> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii"; format=flowed X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.84 required=5 tests=[AWL=-0.600, DNS_FROM_RFC_POST=1.44] X-Spam-Score: 0.84 X-Spam-Level: X-Archive-Number: 200602/84 X-Sequence-Number: 24094 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 ...."