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.
| Author |
Topic |
|
KevinC
Starting Member
4 Posts |
Posted - 2008-08-22 : 13:11:48
|
| Hello,This is my first time posting. I am new to SQl server and SQL. I am trying to select one of two rows for a customerID from a table based on which row has a more recent date.Both rows have the same key column(CustomerID). I tried 'Group By' with 'Having Max' but it didn't work. Can anyone help me please?!!Thank you !! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-22 : 13:22:23
|
| SELECT t.*FROM YourTable tINNER JOIN (SELECT customerID,MAX(datefield) AS MaxDate FROM YourTable GROUP BY customerID)t1ON t.customerID=t1.customerIDAND t.datefield=t1.MaxDate |
 |
|
|
KevinC
Starting Member
4 Posts |
Posted - 2008-08-22 : 14:05:52
|
| Thank you so much VSAKH16 !! |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-08-23 : 01:16:58
|
quote: Originally posted by KevinC Thank you so much VSAKH16 !!
you're welccome |
 |
|
|
|
|
|