pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Josh Berkus <josh@agliodbs.com>
To: nospam4@pobox.com
To: pgsql-sql@postgresql.org
Subject: Re: A simple join question that may stump you
Date: Thu, 27 Sep 2001 08:32:54 -0700
Message-ID: <web-126749@davinci.ethosmedia.com> (raw)
In-Reply-To: <89c01029.0109251901.3dcb5d77@posting.google.com>

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







view thread (4+ messages)

Message-ID: <web-126749@davinci.ethosmedia.com>
Permalink:  ../web-126749@davinci.ethosmedia.com/
Also on:    postgresql.org/message-id/web-126749@davinci.ethosmedia.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: josh@agliodbs.com, nospam4@pobox.com
  Subject: Re: A simple join question that may stump you
  In-Reply-To: <web-126749@davinci.ethosmedia.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox