X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6129ED1C4ED for ; Mon, 8 Mar 2004 20:46:51 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 11254-04 for ; Mon, 8 Mar 2004 16:46:51 -0400 (AST) Received: from mail.greatgulfhomes.com (unknown [216.94.125.243]) by svr1.postgresql.org (Postfix) with ESMTP id 5CB8DD1B530 for ; Mon, 8 Mar 2004 16:46:49 -0400 (AST) Received: from terrynew2 (firewall.development.greatgulfhomes.com [216.191.203.106]) by mail.greatgulfhomes.com (Postfix) with SMTP id 31BF4366A1A; Mon, 8 Mar 2004 15:50:39 -0500 (EST) From: To: "'Matt Chatterley'" Cc: Subject: Re: Trying to make efficient "all vendors who can provide all items" Date: Mon, 8 Mar 2004 15:45:20 -0500 Message-ID: <012f01c4054e$45dfcf60$2766f30a@development.greatgulfhomes.com> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook 8.5, Build 4.71.2173.0 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 In-Reply-To: Importance: Normal X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/64 X-Sequence-Number: 17163 That's pretty nifty code. It certainly looks nicer, and looks like it would work providing vendor_id&item_id is the pk of item_vendors (and it is). I will let you know if it runs any faster... Thanks Terry Fielder Manager Software Development and Deployment Great Gulf Homes / Ashton Woods Homes terry@greatgulfhomes.com Fax: (416) 441-9085 > -----Original Message----- > From: Matt Chatterley [mailto:zen31329@zen.co.uk] > Sent: Monday, March 08, 2004 3:41 PM > To: terry@ashtonwoodshomes.com > Cc: pgsql-sql@postgresql.org > Subject: RE: [SQL] Trying to make efficient "all vendors who > can provide > all items" > > > Hmm. My PGSQL knowledge is rusty, so this may be slightly > microsoftified.. > > How about just: > > SELECT V.VendorID, V.VendorName, COUNT(IV.ItemID) > FROM Vendor V > INNER JOIN Item_Vendor IV ON IV.VendorID = V.VendorID AND > IV.ItemID IN (1, > 2, 3, 4, 5) > GROUP BY V.VendorID, V.VendorName > HAVING COUNT(IV.ItemID) = 5 >