Re: How would I write this query... - Mailing list pgsql-general

From Michael Glaesemann
Subject Re: How would I write this query...
Date
Msg-id 5C90753A-67A6-4C69-9D07-32C5040D0690@seespotcode.net
Whole thread Raw
In response to How would I write this query...  ("Jim Fitzgerald" <jfitz@spacelink.com>)
List pgsql-general
On May 1, 2006, at 3:32 , Jim Fitzgerald wrote:

>   I have two tables, one of them has names of people and an associated
> integer ID.  The other table is a list of the people (from the
> first table)
> by their ID number that have signed up for a class.  How would I
> write a
> query that would list all the people from the first table that do
> not have
> any entries in the second table?   Basically, I want a listing of
> all my
> people who have not signed up for the class.

What you want is sometimes called a semi-difference. Here's how I'd
do it:

select person_id, person_name
from persons
natural join (
     select person_id
     from persons
     except
     select person_id
     from class_signups
     ) not_yet_signed_up

where persons is your first table and class_signups is your second
table.

Hope this helps!

Michael Glaesemann
grzm seespotcode net




pgsql-general by date:

Previous
From: "A.M."
Date:
Subject: Re: Is PostgreSQL an easy choice for a large CMS?
Next
From: "chris smith"
Date:
Subject: Re: Authentication & connection problems