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 -> Re: Another simple query question

Re: Another simple query question

From: Valery Yourinsky <vsu_at_bill.mts.ru>
Date: Tue, 10 Apr 2001 10:19:30 +0400
Message-ID: <3AD2A5F2.4D7894D5@bill.mts.ru>

Rob Cecil wrote:
>
> Two tables A and B
> B has a one-to-many relationship to A, i.e. has a FK back to A
> B has a single field 'Foo', string type
>
> How would a query be constructed that expresses:
>
> Select all rows in A where A has four related rows in B, with B.Foo
> being 'Black','Yellow','White','Orange'

   I think it should be something like this

   SELECT * FROM a
   WHERE a_id IN

      (SELECT a_id FROM b
       WHERE foo IN ('Black','Yellow','White','Orange')
       GROUP BY a_id
       HAVING COUNT(*) = 4)

Valery Yourinsky

-- 
Oracle8 Certified DBA
Moscow, Russia
Received on Tue Apr 10 2001 - 01:19:30 CDT

Original text of this message

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