View Single Post
  #3  
Old February 4th, 2010, 07:11 PM posted to microsoft.public.access.queries
cinnie
external usenet poster
 
Posts: 67
Default SELECT vs. ORDER BY - order of execution question

hello Karl

I'm having trouble understanding this answer because it makes no use of the
ORDER BY clause. I'm trying to determine whether ORDER BY or SELECT is
processed first in SQL. Any thoughts?
--
cinnie


"KARL DEWEY" wrote:

It seems to process from end to start but not all cases.
This works --
SELECT [Something]+1 AS New, YourTable.Score, YourTable.Grade,
[Score]+[Grade] AS Something
FROM YourTable;

And this --
SELECT YourTable.Score, YourTable.Grade, [Score]+[Grade] AS Something,
[Something]+1 AS New
FROM YourTable;

And this --
SELECT [Score]+[Grade] AS Something, YourTable.Score, YourTable.Grade,
[Something]+1 AS New
FROM YourTable;

--
Build a little, test a little.


"cinnie" wrote:

hello

In SQL, is SELECT executed before ORDER BY, or after. Here's why I'm
confused about this;

Consider table tblEmp with fields EmpID, Name_F, Name_L, Wage

SELECT tblEmpID, tblEmp.Name_F & ", " & tblEmp.Name_L AS Name_Full
FROM tblEmp
ORDER BY tblEmp.Wage

This works fine, even though the Wage field in the ORDER BY statement is not
included in the SELECT statement. This makes me think that ORDER BY is
executed BEFORE the SELECT statement has been able to eliminate the Wage
column.

Also, SELECT tblEmpID, tblEmp.Name_F & ", " & tblEmp.Name_L AS Name_Full
FROM tblEmp
ORDER BY Name_Full

This doesn't work because the ORDER BY statement doesn't recognize
Name_Full. This again makes me think that the ORDER BY is executed BEFORE
the SELECT.

But.....

when I research SQL order of operations, most sites seem to claim that the
ORDER BY clause is executed AFTER the SELECT clause. What gives? Any
clarification?

thank you in advance
--
cinnie