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

Home -> Community -> Usenet -> c.d.o.server -> Re: UNION ALL and ordering

Re: UNION ALL and ordering

From: <chrism778_at_gmail.com>
Date: Fri, 23 Nov 2007 07:41:09 -0800 (PST)
Message-ID: <3c5e5c6c-f045-4d92-9af6-e719863fbd57@i29g2000prf.googlegroups.com>


Thanks! The solution to the problem I'm trying to solve will be much simpler now.

On Nov 23, 9:52 am, "Ravip via DBMonster.com" <u36659_at_uwe> wrote:
> By default the output will be result of first select and then second select.
>
>
>
> chrism..._at_gmail.com wrote:
> >When I UNION ALL two sql statements, I need the results from the first
> >statement to come back first in the result set. So if I do something
> >like:
>
> >select col1, col2, ... from table1 order by col2
> >UNION ALL
> >select col1, col2, ... from table2 order by col3
>
> >can I always assume that the results will come back with table1 rows
> >first followed by the table2 results? From some limited testing, this
> >appears to be the case, but is Oracle designed to work this way, or
> >have I just been lucky?
>
> >If this isn't the case, then I would have to add a pseudo column and
> >sort by it like this:
>
> >select 1, col1, col2, ... from table1 order by col2
> >UNION ALL
> >select 2, col1, col2, ... from table2 order by col3
> >ORDER BY 1
>
> >The problem with this approach, is that any order bys I do in the
> >individual select statements may no longer be valid because of the
> >"ORDER BY 1" for the UNION.
>
> --
> Message posted viahttp://www.dbmonster.com
Received on Fri Nov 23 2007 - 09:41:09 CST

Original text of this message

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