A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
SQL query help
Joined: Jun 12, 2005
Sep 17, 2008 07:30:00
I have table with columns as name, deptno and salary.
I need to get the names which has maximum salary in their deptmenets.
I could able to find maximum salaries in each department using
select depno, max(sal) from emp GROUP BY deptno;
But how to get correspodning names?
5.0, SCWCD 1.4
Joined: Oct 13, 2005
Sep 17, 2008 08:12:00
Add "name" to the fields to be selected?
Add: That would probably work for a simple query, but you might need nested "selects" for anything more complicated.[/edit]
[ September 17, 2008: Message edited by: Campbell Ritchie ]
Joined: Aug 13, 2004
Sep 17, 2008 08:18:00
Which Database are you using ?
you can try this query, I haven't tested it
select name, depno, sal from emp where (depno, sal) in (
select depno, max(sal) from emp GROUP BY deptno)
[ September 17, 2008: Message edited by: Shailesh Chandra ]
Gravitation cannot be held responsible for people falling in love ~
rocket mass heater
subject: SQL query help
Expressing a One to Many Relationship in a Single Row
Salary range in singapore for java/j2ee of 5.5+ experience
Query -- select maximum salary in a sum table
how to do this?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2014