SQL Question

From: "Igor Kryltsov" <kryltsov(at)yahoo(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: SQL Question
Date: 2004-11-19 05:57:01
Message-ID: cnk1t6$2c2g$1@news.hub.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi,

If anybody can offer better SQL query please.
We have table
create table group_facility (
group_id integer not null,
facility_id integer not null
)
It stores facilities membership in group. For example: "North Region" -
facilityA, facilityB
I need to extract groups from this table which contain facilityN AND
facilityZ and may be others but these two(both) has to be a group member.

Query:
SELECT DISTINCT group_id FROM facility_group s1
WHERE EXISTS (SELECT 1 FROM facility_group s2 WHERE s2.group_id =
s1.group_id AND facility_id = 390)
AND
EXISTS (SELECT 1 FROM facility_group s2 WHERE s2.group_id = s1.group_id AND
facility_id = 999)

works but what if I need to find groups where membership is (facilityN1,
....facilityN100)??

Thank you,

Igor K

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Thomas F.O'Connell 2004-11-19 06:07:55 Re: Comparing Dates
Previous Message Greg Stark 2004-11-19 05:50:26 Re: Comparing Dates