Select The Database, Getting All The Maximum Values Of A Column
I have the following table: id | value | data | v 1 | val1 | dat1 | 1 2 | val1 | dat2 | 2 3 | val1 | dat3 | 3 4 | val2 | dat4 | 1 What I do is grab the data, each value, w
Solution 1:
You need to identify the max value in a subquery and then join against the constant element
Fiddle
select *
from
Table1
join
(select max(v) MAXV, value from Table1 group by value) T
on T.MAXV = Table1.v and T.value=Table1.value
Solution 2:
As gillyspy already commented, what you need is a subquery that returns the correct values. Check this code:
SELECT id, table1.value, data, v
FROM Table1
JOIN (SELECT MAX(v) MAXV, value
FROM Table1
GROUP BY value
) T ON T.MAXV = Table1.v
AND T.value = Table1.value;
Post a Comment for "Select The Database, Getting All The Maximum Values Of A Column"