How can I only return the first distinct match of a field in MySQL?
My Table:
name hash
----------------
Anna ABC
Barb DEF
Charlie GHI
Anna JKL
Andrea MNO
My Query (for %An%
) :
SELECT DISTINCT(name) as name, hash FROM my_table WHERE name LIKE '%An%';
This returns:
name hash
----------------
Anna ABC
Anna JKL
Andrea MNO
Instead of: (the result I'm after)
name hash
----------------
Anna ABC
Andrea MNO
How can I get only the first match of each distinct name?
I want to return the first Anna
, skip the second (and any subsequent matches), but still get Andrea
(and any further distinct matches, like Andrew
or Anthony
).
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…