My data looks like this:
id name score
--------------------
a apple 0.2
a apple 0.7
a apple 1.1
a banana 1.2
b cherry 0.8
b lemon 0.9
c mango 2.4
c raspberry 1.9
d strawberry 0.7
d lemon 1.1
For each id, I want to select the row with the highest score, but only the id and name:
id name
----------
a banana
b lemon
c mango
d lemon
The following query does the job with sqlite. (It is explained in this answer, why this query is actually invalid in most DBMSs):
SELECT id, name from (SELECT id, name, max(score) from data group by id);
The question is: Is this possible without a subquery?
Notes: I am using sqlite at the moment, but I am looking for a portable solution. If there are only vendor-specific solutions, it is also a valid answer. This question is similar, but the necessity of subqueries is not discussed.