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

Home -> Community -> Mailing Lists -> Oracle-L -> RE: Silly SQL Question

RE: Silly SQL Question

From: Bellow, Bambi <bbellow_at_chi.navtech.com>
Date: Mon, 17 Nov 2003 09:14:26 -0800
Message-ID: <F001.005D6F09.20031117091426@fatcity.com>


Jacques --

Huh? I thought the question was, "give me all the usrs where there exists a record containing a 1,5, and 7". How can that return one record, when there are two users -- and only two users -- who have the 1,5,7 combination? The data provided shows that both GAP and GPA have a 1, 5 and 7 and that no other users do. My query provides that answer. If that wasn't the question, then that won't be the answer; but if it *was* the question, then the query is correct.

HTH,
Bambi.


create table gab (usr char(3),val number);
insert into gab values ('GAP',1);
insert into gab values ('GAP',5);
insert into gab values ('GAP',5);
insert into gab values ('GAP',7);
insert into gab values ('PAG',1);
insert into gab values ('PAG',7);
insert into gab values ('PAG',2);
insert into gab values ('JKL',1);
insert into gab values ('JKL',5);
insert into gab values ('JKL',5);
insert into gab values ('GPA',1);
insert into gab values ('GPA',5);
insert into gab values ('GPA',7);
insert into gab values ('GPA',8);

 select usr from gab
 where val=1
 intersect
 select usr from gab
 where val=5
 intersect
 select usr from gab
 where val=7;

USR

---
GAP
GPA



-----Original Message-----
Sent: Friday, November 14, 2003 7:24 PM
To: Multiple recipients of list ORACLE-L



> -----Original Message-----
> Bellow, Bambi
>
> Why not do it like this...
>
> select usr from gab
> where val=1
> intersect
> select usr from gab
> where val=5
> intersect
> select usr from gab
> where val=7;
Because that way you would get the wrong answer. With the sample data as kindly provided by Mr. Begun the correct query would return one row, but your query returns two rows. SQL> select * from gab ; USR VAL ---------- --------- GAP 1 GAP 5 GAP 5 GAP 7 PAG 1 PAG 7 PAG 2 JKL 1 JKL 5 JKL 5 GPA 1 GPA 5 GPA 7 GPA 8 14 ligne(s) sélectionnée(s). SQL> select usr from gab 2 where val=1 3 intersect 4 select usr from gab 5 where val=5 6 intersect 7 select usr from gab 8 where val=7; USR ---------- GAP GPA -- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Jacques Kilchoer INET: Jacques.Kilchoer_at_quest.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing). -- Please see the official ORACLE-L FAQ: http://www.orafaq.net -- Author: Bellow, Bambi INET: bbellow_at_chi.navtech.com Fat City Network Services -- 858-538-5051 http://www.fatcity.com San Diego, California -- Mailing list and web hosting services --------------------------------------------------------------------- To REMOVE yourself from this mailing list, send an E-Mail message to: ListGuru_at_fatcity.com (note EXACT spelling of 'ListGuru') and in the message BODY, include a line containing: UNSUB ORACLE-L (or the name of mailing list you want to be removed from). You may also send the HELP command for other information (like subscribing).
Received on Mon Nov 17 2003 - 11:14:26 CST

Original text of this message

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