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: rewriting query without using UNION

Re: rewriting query without using UNION

From: <ryan_oracle_at_cox.net>
Date: Wed, 29 Oct 2003 10:29:33 -0800
Message-ID: <F001.005D4F47.20031029102933@fatcity.com>


from basic set theory:

union = OR
intersect = AND

 select e.id, e.name, d.deptname from emp e, dept d  where e.deptno=d.deptno and e.name='JOSE' or d.deptno = 50;  

>
> From: "Linda Wang" <lwang344_at_hotmail.com>
> Date: 2003/10/29 Wed PM 12:54:26 EST
> To: Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com>
> Subject: rewriting query without using UNION
>
> Hi,
> I wonder if there's a better way of writing the query below. Basically, I
> would like to return employee records where employee name='JOSE' + all
> employees in deptno=50. My query can have multiple 'OR' criterias where the
> next criteria maybe returning all employees with salary>60000 in addition to
> the above two criterias. Building the query with multiple UNIONs will
> definitely degrade the query performance. Is there a better way of rewriting
> the query?
>
> Thanks!
>
> linda
>
> select e.id, e.name, d.deptname from emp e, dept d
> where e.deptno=d.deptno and e.name='JOSE'
> union
> select e.id, e.name, d.deptname from emp e, dept d
> where e.deptno=d.deptno and d.deptno=50;
>
> _________________________________________________________________
> Want to check if your PC is virus-infected? Get a FREE computer virus scan
> online from McAfee.
> http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963
>
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> --
> Author: Linda Wang
> INET: lwang344_at_hotmail.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: <ryan_oracle_at_cox.net
  INET: ryan_oracle_at_cox.net

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 Wed Oct 29 2003 - 12:29:33 CST

Original text of this message

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