How to select distinct value from one column only
mysql
Solution
Query:
SELECT `key`, MAX(`name`) as name
FROM `table`
GROUP BY `key`
Problem
I have records as follows: ``` key | name -------------- 1111 | aa 1111 | bb 2222 | cc ``` I need to select the `key` and `name` when the `key` value is distinct. When I tried: ``` select distinct key, name from table; ``` I got all the rows since the query takes distinct for the combination of the columns: `key` and `name`. But, what I need is only distinct `key` and I don't care about the `name`. I have a lot of records, so I need a practical method.