I\'m trying to get the row with the highest/lowest number, after performing a GROUP BY
:
Here is my test data
mysql> SELECT * FROM tes
I think this is what you are trying to achieve:
SELECT t.* FROM test t
JOIN
( SELECT Name, MIN(Value) minVal
FROM test GROUP BY Name
) t2
ON t.Value = t2.minVal AND t.Name = t2.Name;
Output:
ID | VALUE | NAME |
---|---|---|
1 | 10 | row1 |
4 | 5 | row2 |
See this SQLFiddle
Here I have self-joined the table with minVal and Name.