Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get last record

Status
Not open for further replies.

Machlink

Technical User
Apr 3, 2004
25
CA
I have tbl payment with AcctNo, amount, Due date fields. How to get last duedate records from the tbl if you have multiple duedate records
 
You want to get ALL records with the latest due date? Or do you want to get just ONE record?

*cLFlaVA
----------------------------
A polar bear walks into a bar and says, "Can I have a ... beer?"
The bartender asks, "What's with the big pause?
 

SELECT TOP 1 FROM Payment ORDER BY DueDate DESC

This gives only one record

but if you want last record for every account number...do something like this:

SELECT t1.*
FROM [MyTable] t1
WHERE t1.Duedate In (select top 1 t2.Duedate from [MyTable] t2 where t2.AccNo = t1.AccNo ORDER BY t2.Duedate Desc);



-VJ
 
I want to get Acct no, amount, duedate for the last record in the table.

Thanks
 
Try this:

SELECT Top 1 Acctno, amount, duedate from payment order by duedate desc

If you have any recordID column in your table...

if so...try this:

SELECT Top 1 Acctno, amount, duedate from payment order by recordID desc

-VJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top