Imagine a table of name, dept, salary
I want the results to be: for each department, i want
to know what the max salary is and the name of the person with this salary.
i've found an example which suggest the following would work:
However this results in many results per department, the
GROUP BY seems to be looking for unique (dept, name) combinations.
If I omit 'name' from the GROUP BY it complains that each
field in the SELECT must be in an aggregate function or the GROUP BY clause.
Can what I need be done in SQL?
Keven.
I want the results to be: for each department, i want
to know what the max salary is and the name of the person with this salary.
i've found an example which suggest the following would work:
Code:
SELECT name, max(salary), dept
FROM employee
GROUP BY dept, name
GROUP BY seems to be looking for unique (dept, name) combinations.
If I omit 'name' from the GROUP BY it complains that each
field in the SELECT must be in an aggregate function or the GROUP BY clause.
Can what I need be done in SQL?
Keven.