Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Usenet -> c.d.o.server -> Re: dificult SQL
select customer,inc from table1
union select customer,inc from table2
order by inc;
"Order by" is applied after "union", so you use it just once. Inc refers to the second column in the first select, and therefore implicitly refers to the second column of all selects. You can also say:
select customer,inc from table1
union select customer,inc from table2
order by 2;
to explicitly specify column #2. If the second column in the first query is an expression without an alias, you have to use the latter syntax.
-- Roy Brokvam Theory is when you know why it doesn't work. Practice is when it works, but you don't know why. We combine theory and practice; It doesn't work, and we don't know why. chemarey_at_my-deja.com wrote in message <93fc5f$r03$1_at_nnrp1.deja.com>...Received on Tue Jan 09 2001 - 10:46:35 CST
>Hi. I'd like to know how can i order the elements of a query with UNION.
>
>For example:
>
> select customer,inc from table1
>UNION
> select customer,inc from table2
>
>The idea is order by the inc item, but DBMS returns an error if a put
>the order by clause in the two different selects like
>
> select customer,inc from table1 order by inc asc
>UNION
> select customer,inc from table2 order by inc asc.
>
>Do you know if is possiblke to do this and how can i do.
>
> Thanks.
>
>
>Sent via Deja.com
>http://www.deja.com/