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

Home -> Community -> Usenet -> comp.databases.theory -> Re: How to identify a column in order by clause

Re: How to identify a column in order by clause

From: doichi <doichinka_at_abv.bg>
Date: 7 Jan 2005 01:03:34 -0800
Message-ID: <1105088614.586489.269580@f14g2000cwb.googlegroups.com>


I would go for the alias if had to choose between alias and tbl.col notation, but there is better alternative:

Almost sure that Oracle will not accept tbl.col notation in ORDER clause if alias is present (Sorry just uninstalled Oracle and can not test it).
MS SQL is more generous and allows any permutation (tbl.aslias, tbl.col, alias...).
MS Jet DB engine howerver does not allow aliases in ORDER BY clause. MySQL and Postgre have no problems with aliases in ORDER BY clause.

All of the reviewed db engines work fine with 1, 2, n (positional notation) in the ORDER BY clause. So if you want "write once run anywhere" I would go with positional ORDER BY notation like this: SELECT [emp.]empno [AS alias], [emp.]ename [AS alias], [emp.]sal [AS alias]
FROM emp [AS alias]
ORDER BY 1, 2 BR,
Doich

todd_run wrote:
> The question I have is: In a select statement that uses column
> aliases, should the order by clause include the column name or the
> column alias?
>
Received on Fri Jan 07 2005 - 03:03:34 CST

Original text of this message

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