Received: from mail.postgresql.org (webmail.postgresql.org [216.126.85.28]) by mail.postgresql.org (8.11.1/8.11.1) with SMTP id f0IJDd091352 for ; Thu, 18 Jan 2001 14:13:39 -0500 (EST) (envelope-from pgsql-general-owner@postgresql.org) Received: from henry.newn.cam.ac.uk (henry.newn.cam.ac.uk [131.111.204.130]) by mail.postgresql.org (8.11.1/8.11.1) with ESMTP id f0IEwr060953; Thu, 18 Jan 2001 09:58:53 -0500 (EST) (envelope-from prlw1@newn.cam.ac.uk) Received: from [131.111.204.180] (helo=quartz.newn.cam.ac.uk) by henry.newn.cam.ac.uk with esmtp (Exim 3.13 #1) id 14JGWI-0000D7-00; Thu, 18 Jan 2001 14:58:34 +0000 Received: from prlw1 by quartz.newn.cam.ac.uk with local (Exim 3.13 #1) id 14JGVI-0000zO-00; Thu, 18 Jan 2001 14:57:32 +0000 Date: Thu, 18 Jan 2001 14:57:32 +0000 From: Patrick Welche To: "Diehl, Jeffrey" Cc: pgsql-sql@postgresql.org, pgsql-general@postgresql.org Subject: Re: Help with query. (*) Message-ID: <20010118145732.F29761@quartz.newn.cam.ac.uk> Reply-To: prlw1@cam.ac.uk References: Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2i In-Reply-To: ; from jdiehl@sandia.gov on Tue, Jan 16, 2001 at 01:42:45PM -0700 X-Archive-Number: 200101/856 X-Sequence-Number: 3073 On Tue, Jan 16, 2001 at 01:42:45PM -0700, Diehl, Jeffrey wrote: > I'm having difficulty writing a query which I really can't live without... > > I need to get a list of records from table A for which there are > corresponding records in table B. I've tried to use the intersect clause, > but it doesn't seem to work, or it runs far too long. For example: > > select * from A > where 1=1 > intersect select * from A where > B.x=A.x > and A.y=B.y > and A.z=B.z > limit 100 > > I need the most efficient method possible; my A tables have upward of 5 > Million records. The B table, btw, only has about 100 records. Guessing - my system isn't in a state to test just at the minute - is it select A.* from A,B where A.x=B.x and A.y=B.y and A.z=B.z limit 100 that you want?