Reputation: 1159
I have a table like below:
CODE | DATA |
-----+------+--
asd | 1 |
asd | 2 |
asd2 | 3 |
asd4 | 3 |
asd4 | 2 |
I am trying to select the minimum data
for each code, so that only one should be selected for the given code, wanted result is
CODE | DATA |
-----+------+--
asd | 1 |
asd2 | 3 |
asd4 | 2 |
I have tried
Select code, min(data) from myTable group by code, data;
The result I get is only grouping of similar codes but not selecting the minimum of data only
Upvotes: 1
Views: 35
Reputation: 521249
Just aggregate over the code
, but not the data:
SELECT code, MIN(data) AS min_data
FROM myTable
GROUP BY code;
Upvotes: 2