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
 selecting top row after sorting

Author  Topic 

saurabhjj
Starting Member

13 Posts

Posted - 2008-02-29 : 02:06:12
hi,

i have a table emp, whose primary key is empid(varchar2),

i want to sort the empid and select the top row after sorting,

i can sort the table using "select * from emp order by empid desc,

i can select the top row using "select * from emp where rownum=1"

i want a combination of the 2,

pls provide me the required query


Thanks and Regards,
Saurabh Jhunjhunwala

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-29 : 02:13:42
[code]select top 1 * from emp order by empid desc[/code]

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

saurabhjj
Starting Member

13 Posts

Posted - 2008-02-29 : 02:16:02
sorry the query you supplied did not work,
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2008-02-29 : 02:18:26
Well, then you should supply some information. Are you really using SQL Server? Which version? Where is sample data? What is the expected output?

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-02-29 : 02:38:36
This also looks like a ORACLE question.
Microsoft SQL Server does not have a VARCHAR2 datatype. It has NVARCHAR.




E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-02-29 : 05:29:36
Select * from
(
select * from emp order by empid
) t
where rownum=1

Post oracle questions at www.orafaq.com


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -