Assuming we have a table called "mytable" with structure and data like following:
UnqId SrlNum Qty
00001 000001 100
00002 000001 102
00003 000001 101
You can use the following query to get the last row in group by SrlNum:
SELECT m1.* FROM mytable m1 WHERE m1.UnqId IN
( SELECT MAX(m2.UnqId) FROM mytable m2
WHERE m2.SrlNum = m1.SrlNum )
Just for a single group, you can use simpler query:
SELECT TOP 1 * FROM mytable
WHERE SrlNum = '000001' ORDER BY UnqId
by Sergey Berezniker and Michael Levy on thread #735831 |