I have this table entry
:
A | B | C |
---|---|---|
a1 | 1 | c1 |
a1 | 2 | c2 |
a1 | 3 | c3 |
a2 | 2 | c4 |
a2 | 5 | c5 |
a2 | 7 | c6 |
What I want is a for every unique A, get only the first row ordered by its value on column B. Desired output is to have minimum B for each distinct key on column A, like this:
A | B | C |
---|---|---|
a1 | 1 | c1 |
a2 | 2 | c4 |
I know how to do this for any known key, but how do I loop over all distinct keys on column A?
-- for one given key
SELECT entry.*
FROM entry
WHERE entry.A = 'a2'
ORDER by entry.B
LIMIT 1;