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.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 need help to display the latest record

Author  Topic 

Idyana
Yak Posting Veteran

96 Posts

Posted - 2012-02-16 : 10:28:17
I've table and data as following,
declare @t1 table
(idNo varchar(100), myGroup char(1), gradDte date)

insert into @t1 values('1925','K','20010713')
insert into @t1 values('1925','K','19990213')
insert into @t1 values('1925','K','19991113')
insert into @t1 values('4474','J','20021023')
insert into @t1 values('4474','J','19990713')
insert into @t1 values('4474','J','20010211')


I need to display the latest gradDte by idNo and myGroup. My expected result as following,

idNo         | myGroup          | gradDte
-----------------------------------------------
1925 K 2001-07-13
4474 J 2002-10-23


looking for help

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-02-16 : 10:32:25
[code]
select idNo, myGroup, max(gradDte)
from @t1
group by idNo, myGroup
[/code]


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Idyana
Yak Posting Veteran

96 Posts

Posted - 2012-02-16 : 10:36:31
tq khtan
Go to Top of Page
   

- Advertisement -