SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

donjt81
Starting Member

11 Posts

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

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.


blindman
Flowing Fount of Yak Knowledge

USA
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

khtan
In (Som, Ni, Yak)

Singapore
17595 Posts

Posted - 05/14/2007 :  18:45:49  Show Profile  Reply with Quote
Select max(custID) from custInfo where custID <> '0'



KH

Go to Top of Page
  Previous Topic Topic Next Topic  
 New 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.05 seconds. Powered By: Snitz Forums 2000