views:

23

answers:

1

Consider my query,

Select EmpId,RemainingBalance from Salary where EmpId='15'

My results pane,

15 450.00
15 350.00
15 250.00

How to get last RemainingBalance amount (ie) 250.00...

+1  A: 

Presumably you have a datetime in the table that can be used to determine which is the latest record, so you can use this:

SELECT TOP 1 EmpId, RemainingBalance 
FROM Salary
WHERE EmpId = '15'
ORDER BY SomeDateTimeField DESC

If you don't have such a datetime field that indicates when a record was created, then you need another field that can be used to imply the same (e.g. an IDENTITY field, where the greater the number, the more recent the record) - approach would be the same as above.

AdaTheDev
Datetime doesn't have enough resolution (3ms is pretty long time...) to reliably indicate which record is the latest one. At least not in all cases. It's much better solution to use an autoincrement column to order the rows.
Kaniu