Link to home
Start Free TrialLog in
Avatar of gudii9
gudii9Flag for United States of America

asked on

max query

SELECT  Professor_Name , Department , Salary FROM SALARIES GROUP BY (Department ) ORDER BY MAX (Salary ) DESC  LIMIT 1

how above different from below
SELECT  Professor_Name , Department , Max(Salary) FROM SALARIES GROUP BY (Department )

i above query returning only one department instead i need highest salaries of each department. how to fix it
please advise
ASKER CERTIFIED SOLUTION
Avatar of Zakaria Acharki
Zakaria Acharki
Flag of Morocco image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of gudii9

ASKER

SELECT  Professor_Name , Department , Salary FROM SALARIES GROUP BY (Department ) ORDER BY MAX (Salary )
how above  different from below?
SELECT  Professor_Name , Department , Max(Salary) FROM SALARIES GROUP BY (Department )
Given that both queries are syntactically incorrect, I would say nothing.  Neither of those queries run, at least they don't run in my Oracle test database.  To get them to run, you would have to add all the columns that are not aggregated to the group by clause.

The first one would have to be

select Professor_Name , Department , Salary FROM SALARIES GROUP BY (Department, professor_name, salary ) ORDER BY MAX (Salary )

and the second one would have to be

SELECT  Professor_Name , Department , Max(Salary) FROM SALARIES GROUP BY (Department, professor_name )

Can you tell us what you are trying to accomplish, then maybe we can help you get you where you want to go.