Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi everyone..I'me new to the forum. I have an issue and I wouldn't be here if I didn't need this help..I have a table which has several date records under the same ID. For example, I have several Pay Dates from a customer and his ID to identify the payment. Of course, I have MANY MANY different ID's and MANY MANY different pay dates for each ID.How could I extract ONLY the latest pay date for each different ID..????Thanks for the help...
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts
Posted - 2006-09-04 : 11:05:05
[code]Select * from <Your Table > Tbl1 From <Date_Col> = (Select Max(<Date_Col>) From <Your Table> Tbl2 Where Tbl1.ID = Tbl2.ID)[/code]Replace <Your Table> in the query with your table.. and <Date_Col> with the transaction date column.. and finally replace id with one in your table..Chirag
Arnold Fribble
Yak-finder General
1961 Posts
Posted - 2006-09-04 : 11:07:35
Generally something like this:SELECT *FROM CustomerPayments AS C1WHERE pay_date = ( SELECT MAX(pay_date) FROM CustomerPayments AS C2 WHERE C1.customer_id = C2.customer_id )
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts
Posted - 2006-09-04 : 11:10:41
quote:Originally posted by Arnold Fribble Generally something like this:SELECT *FROM CustomerPayments AS C1WHERE pay_date = ( SELECT MAX(pay_date) FROM CustomerPayments AS C2 WHERE C1.customer_id = C2.customer_id )
Chirag
jlara
Starting Member
4 Posts
Posted - 2006-09-04 : 11:33:06
Thank you for the fast reply. Your help with a couple of modifications got for me exactly what I needed.