Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: sql query wanted
Christian, what you want is a listing of ids that exist in all of a
number of subsets.
Therefore, you could
SELECT id FROM foobar WHERE sku = 'a'
which would return:
1
3
5
6
7
To see those which are in two different subsets, you could:
SELECT id FROM foobar WHERE sku = 'a'
AND id IN (SELECT id FROM foobar WHERE sku = 'b')
which would return:
3
6
7
To see those which are in three different subsets, you could:
SELECT id FROM foobar WHERE sku = 'a'
AND id IN (SELECT id FROM foobar WHERE sku = 'b')
AND id IN (SELECT id FROM foobar WHERE sku = 'c')
which would return:
7
You could also use a "SET OPERATOR" called INTERSECT which essentially does the same thing:
SELECT id FROM foobar WHERE sku = 'a'
INTERSECT
SELECT id FROM foobar WHERE sku = 'b'
INTERSECT
SELECT id FROM foobar WHERE sku = 'c'
(Don't quote me on the syntax however, look it up in the reference manual.)
The problem you will run into using this method is that it gets cumbersome if you're looking for the ids that have a, b, c, d, e, f, g,...x, y, and z! Received on Fri Feb 22 2002 - 10:38:22 CST
![]() |
![]() |