SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 precedence
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

ghostrider
Starting Member

India
11 Posts

Posted - 02/10/2013 :  07:56:33  Show Profile  Reply with Quote
Why is it necessary to precede group by before order by and not vice versa in a sql query??
as the foll code gives an error
select name from student order by age group by name;

webfred
Flowing Fount of Yak Knowledge

Germany
8765 Posts

Posted - 02/10/2013 :  08:11:50  Show Profile  Visit webfred's Homepage  Reply with Quote
Why do think about it?
Your question could also be: Why can't we write "FROM Student SELECT name"?
But it is clear: ORDER BY works on the resultset so it should be at the end of the statement.


Too old to Rock'n'Roll too young to die.
Go to Top of Page

ghostrider
Starting Member

India
11 Posts

Posted - 02/10/2013 :  08:48:48  Show Profile  Reply with Quote
Thank you @webfred!!!
Go to Top of Page

James K
Flowing Fount of Yak Knowledge

3724 Posts

Posted - 02/10/2013 :  11:31:36  Show Profile  Reply with Quote
Another way to look at it is that, that is just the way the syntax is. In LINQ queries, the syntax starts with the from clause as WebFred suggested. Doesn't matter how the server processes the query or how the physical processing takes place, it is just that the syntax rules require it.

If you are interested in the logical query processing phases, sqlauthority.com has a brief description http://blog.sqlauthority.com/2009/04/06/sql-server-logical-query-processing-phases-order-of-statement-execution/ As suggested in that article, a more detailed explanation is available in the the book "Inside Microsoft SQL Server 2008: T-SQL Querying"
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000