Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> SQL for
Hello, I was wondering if someone could help me with a query. I have
found a long, rather convoluted inefficient way to do it and I am
wondering if there is a better one. If I have a table like so:
foobar
foo | bar
|
1 | a 1 | b 1 | c 2 | a 3 | a 3 | b
I wish to get all the "bar"s which have "foo"s of 1, 2 and 3. So the answer above is "a". The query I came up with is:
SELECT bar FROM foobar WHERE foo = 1 INTERSECT SELECT bar FROM foobar WHERE foo = 2 INTERSECT SELECT bar FROM foobar WHERE foo = 3;
Ugly and cumbersome. What do you think? Is there something a bit more elegant?
Dan
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Fri Nov 19 1999 - 00:30:37 CST