mysql - Getting the maximum value from the group -
i have table structure
emp_id emp_name emp_sal depat 1 ab 10000 2 cb 12000 3 da 7000 b 4 sb 2000 b 5 6000 6 cf 10000 b 7 ak 8000 c 8 lm 6000 c i need result maximum emp_sal each depart group depart
emp_name emp_sal depart cb 12000 cf 10000 b ak 8000 c
i wrote query :
select distinct (emp_sal) , depart emp group depart having emp_sal = (select max(emp_sal) emp group depart ) but did not work. tried several other queries did not desired result.
to answer question stated:
select max(emp_sal), depart emp group depart however, suspect want whole row max salary each department:
select emp_name, emp_sal, depart (select * emp order emp_sal desc) x group depart note: mysql-only solution (with whacky group by) question tagged mysql , works :)
Comments
Post a Comment