My table looks like this :
I want to find the id having max age from each skills in skills column. So the answer for this table will be Cooking->r1, Eating->r2 and Coding->r3.
How can I accomplish this?
My table looks like this :
I want to find the id having max age from each skills in skills column. So the answer for this table will be Cooking->r1, Eating->r2 and Coding->r3.
How can I accomplish this?
Do a GROUP BY
in a sub-query to find each skill's max age. JOIN
with that result.
SELECT t.id, t.age, t.skills
FROM tablename t
join (select skills, max(age) as maxage
from tablename
GROUP BY skills) t2
on t.skills = t2.skills and t.age = t2.maxage
Note: Ties will be included. (If there are two id's with same max age for a skill, both will be returned.)