Help to simplify sample query - Mailing list pgsql-sql

From Daniel Henrique Alves Lima
Subject Help to simplify sample query
Date
Msg-id 404D5920.40104@yahoo.com.br
Whole thread Raw
Responses Re: Help to simplify sample query  (Tomasz Myrta <jasiek@klaster.net>)
Re: Help to simplify sample query  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-sql
Hi guys, i have a new question about how to simplify a query. I have 
the tables area_course(cd_area,cd_course) and 
teacher_course(cd_teacher,cd_course) and a set of pairs of values 
{(1,2),(98,45),(11,0),...}.
   Now, i must to select the areas which courses appears in 
teacher_course and match with the set of pairs. Something like :

select cd_area from area a1 where  exists (select * from teacher_course c2 where c2.cd_course = 
a1.cd_course and c2.cd_teacher = 1 and c2.cd_course = 2) and  exists (select * from teacher_course c2 where
c2.cd_course= 
 
a1.cd_course and c2.cd_teacher = 98 and c2.cd_course = 45) and  exists (select * from teacher_course c2 where
c2.cd_course= 
 
a1.cd_course and c2.cd_teacher = 11 and c2.cd_course = 0) and
....
   This is just a sample. The whole query is giant and its use other 
tables/columns. Is there a best way to write this query ?
   I don't think this is possible, but: Is there a efficient way to 
compare if the result of a query is a superset of the result of another ?



   I would appreciate any ideas/suggestions. Thanks !!!




pgsql-sql by date:

Previous
From: "Iain"
Date:
Subject: Re: Simple SQL question
Next
From: Daniel Henrique Alves Lima
Date:
Subject: Re: Simple SQL question