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.
| Author |
Topic |
|
shaggy
Posting Yak Master
248 Posts |
Posted - 2009-11-24 : 06:55:26
|
| Hi,should i need to include order by asc clause for column which i used in select list with distinct keyword.Eg:select distinct col1 from tablename order by col1kindly advicePlease reply any web site for reference |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-24 : 07:23:57
|
In relation to your given example - no.In my simple words:The distinct is used to build the record set.The order by is used to order the already builded record set. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
kbhere
Yak Posting Veteran
58 Posts |
|
|
shaggy
Posting Yak Master
248 Posts |
Posted - 2009-11-24 : 08:13:40
|
| Thanks webfredwhen we use distinct automatically the recordset is sorted according to the distinct column list iam looking for any documents whether the above said is exact |
 |
|
|
rajdaksha
Aged Yak Warrior
595 Posts |
Posted - 2009-11-24 : 08:20:00
|
| HiIf we distinct col the records are automatically sorted.For Desc SELECT DISTINCT(OBJECT_ID) FROM SYS.OBJECTS ORDER BY OBJECT_ID desc -------------------------R... |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-11-24 : 08:32:23
|
quote: Originally posted by shaggy Thanks webfredwhen we use distinct automatically the recordset is sorted according to the distinct column list iam looking for any documents whether the above said is exact
In my simple words:It is a side effect from the work to have distinct data...Don't know where it is to find in a document.But I NEVER would assume that it always will happen like expected.I always would write my ORDER BY if I want a sorted output. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
|
|
|