Path: dp-news.maxwell.syr.edu!spool.maxwell.syr.edu!drn.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.icl.net!newsfeed.fjserv.net!newspump.monmouth.com!newspeer.monmouth.com!newsfeed.yul.equant.net!newsread.com!newsprint.newsread.com!postnews.google.com!c13g2000cwb.googlegroups.com!not-for-mail
From: "-CELKO-" <jcelko212@earthlink.net>
Newsgroups: comp.databases.theory
Subject: Re: How to identify a column in order by clause
Date: 31 Dec 2004 21:38:51 -0800
Organization: http://groups.google.com
Lines: 15
Message-ID: <1104557931.005232.8560@c13g2000cwb.googlegroups.com>
References: <1104534959.058255.150190@z14g2000cwz.googlegroups.com>
NNTP-Posting-Host: 63.246.173.210
Mime-Version: 1.0
Content-Type: text/plain; charset="iso-8859-1"
X-Trace: posting.google.com 1104557936 7384 127.0.0.1 (1 Jan 2005 05:38:56 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Sat, 1 Jan 2005 05:38:56 +0000 (UTC)
In-Reply-To: <1104534959.058255.150190@z14g2000cwz.googlegroups.com>
User-Agent: G2/0.2
Complaints-To: groups-abuse@google.com
Injection-Info: c13g2000cwb.googlegroups.com; posting-host=63.246.173.210;
   posting-account=nLdTow0AAAAwp3bRDIfsa6ovxvAU7ruH
Xref: dp-news.maxwell.syr.edu comp.databases.theory:29249

>> 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? <<

Column aliases.  In Standard SQL, the ORDER BY clause is part of a
CURSOR.  The CURSOR sees the result set of the SELECT statement,
converts it into a non-relational sequential file structure and sorts
it if there is an ORDER BY clause.  It does not know about the base
table column names, only the alias name in the result set that is
passed to it.

SQL Server is still based on a file system model from its Sybase "code
museum" heritage, so you can attach ORDER BY in places that should be
illegal.

