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

Home -> Community -> Usenet -> c.d.o.misc -> Re: sql query wanted

Re: sql query wanted

From: Basil Jackson <BJackson_at_BOSGmbH.Com>
Date: 22 Feb 2002 08:38:22 -0800
Message-ID: <adec38b6.0202220838.681c3816@posting.google.com>


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

Original text of this message

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