Reputation: 28905
I have the following table called MyTable
First Second Third Fourth
1 Ab Cd 2.3
1 Cq Fe 3.4
2 Dr Dh 1.2
3 Bb Qd 9.8
..........ETC.....................
How can I select the rows grouped by First that have a maximum Fourth
column value. So it would be a query that results in
First Second Third Fourth
1 Cq Fe 3.4
2 Dr Dh 1.2
3 Bb Qd 9.8
Upvotes: 2
Views: 139
Reputation: 117540
select
B.*
from (select T.First, max(T.Fourth) as Fourth from Table as T) as A
inner join Table as B on B.First = B.First and B.Fourth = A.Fourth
Upvotes: 0
Reputation: 25763
Try this solution:
select MT.First, MT.Second, MT.Third, MT.Fourth
from MyTable MT
join ( select first, max(Fourth) as Fourth
from MyTable
group by first
) T on T.first = MT.First
and T.Fourth = MT.Fourth
Upvotes: 2
Reputation: 24096
try this:
select *
from MyTable T
join (Select First,max(Fourth) as Fourth
from MyTable
group by First)a
on T.First=a.First
and T.Fourth=a.Fourth
Upvotes: 5