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.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to get the first row of a sorted list
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

11 Posts

Posted - 05/14/2007 :  16:40:37  Show Profile  Reply with Quote

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.

Flowing Fount of Yak Knowledge

2365 Posts

Posted - 05/14/2007 :  17:12:22  Show Profile  Reply with Quote
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 - 05/14/2007 :  18:45:49  Show Profile  Reply with Quote
Select max(custID) from custInfo where custID <> '0'


Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000