Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Reg. order by clause

Author  Topic 

vmurali
Yak Posting Veteran

88 Posts

Posted - 2006-08-19 : 05:34:19
Can you explain the below scenario

The ORDER BY clause can include items that do not appear in the select list. However, if SELECT DISTINCT is specified, or if the statement contains a GROUP BY clause, or if the SELECT statement contains a UNION operator, the sort columns must appear in the select list.

what is the reason behind this.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2006-08-19 : 07:51:36
The reason is simple logic. Be sure you fully understand how those operations work and think about it ...

How would you return a list of US states, ordered by city? Or returning a list of all US states and all Fruit ordered by capital? neither makes any sense w/o more information or clearer specs and can be interpreted multiple ways.



- Jeff
Go to Top of Page
   

- Advertisement -