Received: from davinci.ethosmedia.com (davinci.ethosmedia.com [209.10.40.250]) by postgresql.org (8.11.3/8.11.4) with ESMTP id f8RFX3h46969 for ; Thu, 27 Sep 2001 11:33:03 -0400 (EDT) (envelope-from josh@agliodbs.com) Received: from [209.10.40.250] (account ) by davinci.ethosmedia.com (CommuniGate Pro WebUser 3.4.1) with HTTP id 126749; Thu, 27 Sep 2001 08:32:54 -0700 From: "Josh Berkus" Subject: Re: A simple join question that may stump you To: nospam4@pobox.com (Ross Smith), pgsql-sql@postgresql.org X-Mailer: CommuniGate Pro Web Mailer v.3.4.1 Date: Thu, 27 Sep 2001 08:32:54 -0700 Message-ID: In-Reply-To: <89c01029.0109251901.3dcb5d77@posting.google.com> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="_===126749====davinci.ethosmedia.com===_" X-Archive-Number: 200109/251 X-Sequence-Number: 4933 This is a multi-part MIME message --_===126749====davinci.ethosmedia.com===_ Content-Type: text/plain; charset="ISO-8859-1" Content-Transfer-Encoding: 8bit Ross, > ID FLAG > ----- ----- > 1 1 > 2 1 > 2 2 > 3 1 > 3 2 > 3 3 > > and table B: > > FLAG > ----- > 1 > 2 > > I want to find all id's from table A that have every flag in table B > but no extra flags. So, I'd end up with: > > ID > ----- > 2 Try looking at the INTERSECT and EXCEPT join types. Thus, in pseudo-sql you'd need: SELECT A.ID WHERE Count A JOIN B = Count B AND Count A EXCEPT B = 0 Assuming that all rows in A are unique. -Josh ______AGLIO DATABASE SOLUTIONS___________________________ Josh Berkus Complete information technology josh@agliodbs.com and data management solutions (415) 565-7293 for law firms, small businesses fax 621-2533 and non-profit organizations. San Francisco --_===126749====davinci.ethosmedia.com===_ Content-Type: text/plain Content-Disposition: attachment; filename="" Content-Transfer-Encoding: base64 DQo= --_===126749====davinci.ethosmedia.com===_ Content-Type: text/plain Content-Disposition: attachment; filename="" Content-Transfer-Encoding: base64 DQo= --_===126749====davinci.ethosmedia.com===_ Content-Type: text/plain Content-Disposition: attachment; filename="" Content-Transfer-Encoding: base64 DQo= --_===126749====davinci.ethosmedia.com===_--