Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Pick last record from a group of records
Message
From
26/12/2002 16:34:06
 
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Miscellaneous
Thread ID:
00735831
Message ID:
00735943
Views:
7
This message has been marked as a message which has helped to the initial question of the thread.
I'll throw another one into the pot. "Last" infers a relationship between the records, and it has to be something other than position, since SQL Server is free to store the rows on any page of a table, unless a clustered index is in place.


Assuming that the UnqID column is unique and sequential, you can get the last with a query similar to this:

SELECT TOP 1 * FROM thetable WHERE SrlNum = '000001' ORDER BY UnqId

-Mike

>If following is my data and my goal is to pick last record with UnqId = "00003" for SrlNum = "000001", could you suggest me a SELECT statement:
>
>
>UnqId  SrlNum  Qty
>00001  000001  100
>00002  000001  102
>00003  000001  101
>
>
>Basically I want to pick the last transaction that occured for SrlNum = "000001".
>
>Wish you a Very Happy & Exciting New Year! :-)
>Thank you,
Michael Levy
MCSD, MCDBA
ma_levy@hotmail.com
Previous
Reply
Map
View

Click here to load this message in the networking platform