Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.server -> SQL for

SQL for

From: <danielsomerfield_at_my-deja.com>
Date: Fri, 19 Nov 1999 06:30:37 GMT
Message-ID: <812qqd$3i9$1@nnrp1.deja.com>


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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US