Re: SQL question: checking all required items

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: "Raymond O'Donnell" <rod(at)iol(dot)ie>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: SQL question: checking all required items
Date: 2007-08-10 20:29:38
Message-ID: dcc563d10708101329l2b38c6d1w364acc08d3a32e11@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 8/10/07, Raymond O'Donnell <rod(at)iol(dot)ie> wrote:
> - how can I find those people who don't have _all_ of the items which
> are marked "required"?
>
> In other words, how do I select those rows in "people" which don't have
> a corresponding row in "items_for_people" for *each* row in "items"
> which has is_required=true?

Without writing the exact query you need, I'll give you a couple of
ways to solve the problem of finding things in one set that aren't in
another.

select table1.id from table1 left join table2 on (table1.id=table2.id)
where table2.id is null
OR
select table1.id from table1 where table1.id is not in (select id from table2);

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2007-08-10 20:32:34 Re: SQL question: checking all required items
Previous Message Raymond O'Donnell 2007-08-10 20:07:26 SQL question: checking all required items