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 |
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-10-07 : 08:45:52
|
hii have a table like that (simplifieD)ID---Name---Comment---Date1---John---a---01.01.20002---John---b---01.01.20013---Jack---c---02.02.20044---Jack---d---02.02.2005i want to select the Names that have closest date to now.i want a result like this.ID---Name---Comment---Date2---John---b---01.01.20014---Jack---d---02.02.2005MS BLESS US |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-07 : 08:59:00
|
[code]select *from table t inner join ( select ID, max(Date) as max_date from table group by ID ) l on t.ID = l.ID and t.Date = l.max_date[/code] KH |
 |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-10-07 : 09:09:17
|
Select * from table t where Date=(Select Max(Date) from tablewhere ID= t.ID)i tried this but it doesnt work tooyour query didint worked and.MS BLESS US |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-07 : 09:16:44
|
quote: Originally posted by bilencekic Select * from table t where Date=(Select Max(Date) from tablewhere ID= t.ID)i tried this but it doesnt work tooyour query didint worked and.MS BLESS US
Ooops sorryselect *from table t inner join ( select Name, max(Date) as max_date from table group by Name ) l on t.Name= l.Name and t.Date = l.max_date KH |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-10-07 : 09:22:10
|
quote: Originally posted by bilencekic Select * from table t where Date=(Select Max(Date) from tablewhere ID= t.ID)i tried this but it doesnt work tooyour query didint worked and.MS BLESS US
Select * from table t where Date = (Select Max(Date) from table where Name = t.Name) KH |
 |
|
bilencekic
Posting Yak Master
121 Posts |
Posted - 2006-10-07 : 09:23:06
|
saol birader =)(thx very much.)MS BLESS US |
 |
|
|
|
|