How can I only return the first distinct match of a field in MySQL?
My Table:
name hash ---------------- Anna ABC Barb DEF Charlie GHI A
When using GROUP BY, MySQL destroy the desc order on the same query level.
GROUP BY,
Instead of:
SELECT name, hash FROM my_table GROUP BY name ORDER BY name ASC, hash DESC
Use sub query on descending order:
SELECT * FROM( SELECT name, hash FROM my_table ORDER BY name ASC, hash DESC )Q GROUP BY name