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 - UNION statement

Re: SQL - UNION statement

From: Matthias Gresz <GreMa_at_t-online.de>
Date: 8 Dec 1998 10:20:41 GMT
Message-ID: <74iuhp$6l6$2@news00.btx.dtag.de>


suisum_at_ecn.ab.ca schrieb:
>
> Hi all:
>
> Anyone know what the purpose of the following SQL statement? Why we need
> UNION?
>
> CURSOR td_curs IS
> SELECT sum(expen_amount) expen_amount,
> e.disb_no,
> d.description
> from expense e,
> descriptions d,
> disb_table dt
> where e.client_no = :top.client_no
> and e.matter_no = :top.matter_no
> and e.new_journal_type = 'XX'
> and e.disb_no = '000'
> and e.disb_code = d.record_no
> and e.tran_date <= to_date(:TOP.RE_DATE, :TOP.DATE_FORMAT)
> and e.disb_no = dt.disb_no
> group by e.disb_no, description
> UNION
> SELECT sum(expen_amount) expen_amount,
> e.disb_no,
> dt.disb_descrip
> from expense e,
> descriptions d,
> disb_table dt
> where e.client_no = :top.client_no
> and e.matter_no = :top.matter_no
> and e.new_journal_type = 'XX'
> and e.disb_no != '000'
> and e.disb_code = d.record_no
> and e.tran_date <= to_date(:TOP.RE_DATE, :TOP.DATE_FORMAT)
> and e.disb_no = dt.disb_no
> group by e.disb_no, dt.disb_descrip
> order by 2;
>
> --
> Best regards,

As far as I understood the statement, you need the union, since for e.disb_no = '000' description is taken from table 'descriptions ' and for
e.disb_no != '000' description is taken from 'disb_table'. under circumstances you can speed up your query:

HTH
Matthias
--
Matthias.Gresz_at_Privat.Post.DE

Always log on the bright side of life.
http://www.stone-dead.asn.au/movies/life-of-brian/brian-31.htm Received on Tue Dec 08 1998 - 04:20:41 CST

Original text of this message

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