Re: How would I write this query...

From: Michael Glaesemann <grzm(at)seespotcode(dot)net>
To: Jim Fitzgerald <jfitz(at)spacelink(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How would I write this query...
Date: 2006-05-01 13:33:50
Message-ID: 5C90753A-67A6-4C69-9D07-32C5040D0690@seespotcode.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message A.M. 2006-05-01 13:33:52 Re: Is PostgreSQL an easy choice for a large CMS?
Previous Message chris smith 2006-05-01 12:43:29 Re: Authentication & connection problems