How can I return max value and the date from the following table?
declare @t1 table
(
id int,
value int,
date date
)
insert into @t1
select 1, 100, '2017-01-02'
union
select 1, 200, '2017-01-03'
union
select 1, 300, '2017-01-04'
union
select 2, 400, '2017-02-02'
union
select 2, 500, '2017-02-03'
union
select 2, 600, '2017-02-04'
select id, max(value) from @t1 group by id
The following returns max value, but I also need the date from that max value. In this case, it would be 300, '2017-01-04' and 600, '2017-02-04'
Thanks.