Skip to content
Advertisement

Select EMP with max SAL from each DEPT

I´m having a bad time with a SQL query. I´m using oracle default tables:

‘EMP’ TABLE

http://imageshack.us/photo/my-images/850/sinttuloxps.png/

AND

‘DEPT’ TABLE

http://imageshack.us/photo/my-images/19/assayp.png/


I wan´t to get the employee with the highest salary in each department.

I´m using SQLPLUS.

Thanks in advance!

ALSO CODE:

Advertisement

Answer

Classic query. Here is what you want:

Here is a working fiddle: http://sqlfiddle.com/#!4/7147b/6

Additionally, you might want to checkout a different approach. Look here (SQL Select only rows with Max Value on a Column) to see an interesting answer on the topic.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement