Aug 3, 2004 #1 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
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
Aug 3, 2004 #2 cLFlaVA Programmer Jun 14, 2004 6,450 US 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? Upvote 0 Downvote
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?
Aug 3, 2004 #3 amorous Programmer Sep 5, 2003 1,008 US 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 Upvote 0 Downvote
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
Aug 3, 2004 Thread starter #4 Machlink Technical User Apr 3, 2004 25 CA I want to get Acct no, amount, duedate for the last record in the table. Thanks Upvote 0 Downvote
Aug 3, 2004 #5 amorous Programmer Sep 5, 2003 1,008 US 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 Upvote 0 Downvote
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