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
 General SQL Server Forums
 New to SQL Server Programming
 no duplicates

Author  Topic 

basicconfiguration
Constraint Violating Yak Guru

358 Posts

Posted - 2012-07-06 : 17:09:05
declare @ad table (adcontrolid int)
insert @ad
select 1 union all
select 2 union all
select 3 union all
select 4

declare @adevent table (adcontrolid int, moderationdate datetime)
insert @adevent
select 1, getdate() -1 union all
select 1, getdate() union all
select 2, '04-01-2012' union all
select 2, '03-01-2012'

I like to get the latest moderation date. I dont wanna have 4 records result. I just want 2 records, like below.

return:
1, getdate()
2, '04-01-2012'

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-07-06 : 17:11:23
SELECT adcontrolid, MAX(moderationdate) FROM @adevent GROUP BY adcontrolid
Go to Top of Page

basicconfiguration
Constraint Violating Yak Guru

358 Posts

Posted - 2012-07-07 : 22:22:23
That was fast. thank rob!
Go to Top of Page
   

- Advertisement -