Please start any new threads on our new site at 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
 how to get the first row of a sorted list

Author  Topic 

Starting Member

11 Posts

Posted - 2007-05-14 : 16:40:37

I am a newbie so this might be a very basic question. I have a table that not sorted. So I write a query to sort the table like this

Select * from custInfo where custID <> '0' order by custID Desc

Now obviously I have a selection of the original table in desc order. Now I want to get the first custId from thid Desc selection. How do I do this.

So if the unsorted table looked like this

001 Martha
005 Steve
002 Mike
003 David

and the sorted selection looks like this

005 Steve
003 David
002 Mike
001 Martha

And then I want to select Steve's custID which is 005. how do i do this.

Thanks in advance.

Master Smack Fu Yak Hacker

2365 Posts

Posted - 2007-05-14 : 17:12:22
Select TOP 1 * from custInfo where custID <> '0' order by custID Desc

e4 d5 xd5 Nf6
Go to Top of Page

In (Som, Ni, Yak)

17689 Posts

Posted - 2007-05-14 : 18:45:49
[code]Select max(custID) from custInfo where custID <> '0'[/code]


Go to Top of Page

- Advertisement -