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

Home -> Community -> Usenet -> c.d.o.tools -> Re: UNION and ORDER BY

Re: UNION and ORDER BY

From: Brian Tkatch <SPAMBLOCK.Maxwell_Smart_at_ThePentagon.com.SPAMBLOCK>
Date: Wed, 08 Nov 2000 22:34:57 GMT
Message-ID: <3a09d30d.722529515@news.alt.net>

On Wed, 08 Nov 2000 20:25:22 GMT, shaikh74_at_my-deja.com wrote:

>Dear Oracle gurus:
>
>I have two SQL statements which are run through UNION and UNION ALL,
>and the results are exact same. They contain duplicate rows (rows
>which are in common within two SQLs). I would like to get distinct
>rows in the final result set. Also, in the final set I would them to
>run through ORDER BY clause. Your assistance values a million.
>Thanks a bunch. Please reply to shaikh74_at_visto.com
>Asad
>
>
>Sent via Deja.com http://www.deja.com/
>Before you buy.

From Oracle docs:



UNION
 All rows selected by either query.  

UNION ALL
 All rows selected by either query, including all duplicates.  

INTERSECT
 All distinct rows selected by both queries.  

MINUS
 All distinct rows selected by the first query but not the second.




For compound queries (containing set operators UNION, INTERSECT, MINUS, or UNION ALL), the ORDER BY clause must use positions, rather than explicit expressions. Also, the ORDER BY clause can appear only in the last component query. The ORDER BY clause orders all rows returned by the entire compound query.

SELECT 'Brian' INTO Signature FROM Dual; Received on Wed Nov 08 2000 - 16:34:57 CST

Original text of this message

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