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
 Problem with Order by

Author  Topic 

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-11-24 : 01:05:22
Hi,

I m facing problem when try to select specific column value from subquery.

e.g

select name from (select distinct name, age from emp order by name asc,age asc)

thanks in advance



malay

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 01:09:30
No meaning specifying it in subquery. you should be ordering only in final select

select name from (select distinct name, age from emp )t order by t.name asc,t.age asc
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2008-11-24 : 01:40:29
You need to give a name to the derived table

select name from (select distinct name, age from emp order by name asc,age asc) a


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

malaytech2008
Yak Posting Veteran

95 Posts

Posted - 2008-11-24 : 07:00:29
Thanks Visakh, it works fine

malay
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-24 : 07:03:23
welcome
keep in mind that order cant be guarnteed unless you use explicit order by in final select statement
Go to Top of Page
   

- Advertisement -