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 |
stix123123
Starting Member
1 Post |
Posted - 2007-06-22 : 11:19:23
|
I am trying to filter my data set based on taking the latest date for records with the same ID so that after the query I have 1 record per identifier. Heres an example ID Date Data1 1/1/2006 1001 7/1/2006 2001 3/1/2006 3002 5/1/2006 2503 4/1/2006 1003 8/1/2006 150 Desired Output ID Date Data1 7/1/2006 2002 5/1/2006 2503 8/1/2006 150Any help on implementing this would be great. Thanks |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-22 : 11:32:19
|
[code]SELECT *FROM yourtable tWHERE [Date] = (SELECT MAX([Date]) FROM yourtable x WHERE x.[ID] = t.[ID])ORDER BY [ID][/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-22 : 11:33:34
|
Select columns from table T1inner join (Select id,max(date) as date from table group by id) T2on T1.id=T2.id and T1.date=T2.dateI think you need to Learn SQL MadhivananFailing to plan is Planning to fail |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-06-22 : 11:34:08
|
Tan is always fasterMadhivananFailing to plan is Planning to fail |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-06-22 : 11:36:04
|
quote: Originally posted by madhivanan
Tan is always fasterMadhivananFailing to plan is Planning to fail
New version of Bot. With Code formatting [spoiler](on the front end)[/spoiler]  KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|