Re: SQL - filtering data based on AND condition

From: philippe <hay_tray_at_yahoo.fr>
Date: 5 Jun 2003 06:37:54 -0700
Message-ID: <d6b0dfa5.0306050537.655f9f30_at_posting.google.com>


select p.NAME FROM PERSON p where p.PERSON_ID in

    (select ID from

             (select PERSON_ID  ID, count (PERSON_ID) NUM from LANGUAGE_SKILL
              where LANG_ID in (1,2) group by person_id)
     where NUM = 2);

may be there is better solution.

tested with "OracleTool" on http://membres.lycos.fr/pmscontact/

best regards

"gospar" <no.spam_at_my.place> wrote in message news:<bbkrbp$hd9$1_at_sunce.iskon.hr>...
> I wonder if this problem can be solved with one query statement:
>
> CREATE TABLE PERSON(PERSON_ID NUMBER(10),NAME VARCHAR2(50));
> INSERT INTO PERSON VALUES(1,'Mike');
> INSERT INTO PERSON VALUES(2,'John');
> CREATE TABLE LANGUAGE(LANG_ID NUMBER(10),NAME VARCHAR2(50));
> INSERT INTO LANGUAGE VALUES(1,'English');
> INSERT INTO LANGUAGE VALUES(2,'German');
> INSERT INTO LANGUAGE VALUES(3,'Italian');
> CREATE TABLE LANGUAGE_SKILL(PERSON_ID NUMBER(10), LANG_ID NUMBER(10));
> INSERT INTO LANGUAGE_SKILL VALUES(1,1); -- Mike speaks English
> INSERT INTO LANGUAGE_SKILL VALUES(1,2); -- Mike speaks German
> INSERT INTO LANGUAGE_SKILL VALUES(2,1); -- John speaks English
> COMMIT;
>
> Question:
> How to select all persons who speak two (or any number) of selected
> languages.
>
> Example 1: Give me all persons who speak English AND German.
> Result 1: Mike
>
> Example 2: Give me all persons who speak English AND English
> Result 2: Mike, John
>
> Example 3: Give me all persons who speak English AND Italian AND German
> Result 3: none
>
> Note:
> Language and Person table can have any number of rows.
> There should be 3 SELECT statements for this 3 examples which differ only in
> WHERE clause.
Received on Thu Jun 05 2003 - 15:37:54 CEST

Original text of this message