Re: SQL query question

From: Tomasz Myrta <jasiek(at)klaster(dot)net>
To: Joost Kraaijeveld <J(dot)Kraaijeveld(at)Askesis(dot)nl>
Subject: Re: SQL query question
Date: 2004-12-22 13:38:48
Message-ID: 41C978E8.1020002@klaster.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Hi all,
>
> I have 2 tables, with a 1-n relation:
>
> parent( oid, parent_name)
> child(oid, child_name, iod_parent)
>
> How do I get the parent_names of all parents without a child?

select parent_name from parent
left join child on (parent.oid=child.iod_parent)
where child.oid is null;

or

select parent_name from parent
where not exists (select * from child where
child.iod_parent=parent.oid);

Regards,
Tomasz Myrta

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Együd Csaba 2004-12-22 14:09:08 Strange Index behavior
Previous Message vinita bansal 2004-12-22 13:32:14 default index created for primary key