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 |
SQLCM
Starting Member
13 Posts |
Posted - 2007-05-25 : 20:02:27
|
How do I select 3 most recent visit date for each client if the result from the following query returns more than 3 visit dates for each clientSELECT* FROM client_tableResult:last_Name visit_datesmith 2006-01-15smith 2006-02-12smith 2006-04-16smith 2006-05-12smith 2006-09-15smith 2006-02-19kelly 2006-02-13kelly 2006-03-09kelly 2006-06-03kelly 2006-09-11kelly 2006-02-13kelly 2006-05-06kelly 2006-01-13The result I am looking for:last_Name visit_datesmith 2006-09-15smith 2006-05-12smith 2006-04-16kelly 2006-09-11kelly 2006-06-03kelly 2006-05-06Thank you |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-05-25 : 20:55:26
|
[code]select *from client_table cwhere visit_date in (select top 3 visit_date from client_table x where x.last_name = c.last_name order by visit_date desc)[/code] KH |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
|
SQLCM
Starting Member
13 Posts |
Posted - 2007-05-29 : 12:34:28
|
Thank you very much for both of your suggestions! |
 |
|
|
|
|