Click here to Skip to main content
15,894,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have table with column employee name , dept, salary


i want to get max salary in each dept
can any one help me
Posted
Comments
CHill60 6-Feb-15 12:09pm    
What have you tried already and where are you stuck?
Richard Deeming 6-Feb-15 13:29pm    
You're obviously taking the same course as chand5055[^]:
How to get employee names along department names who having highest salary in respective departments.[^]

Have you spent the time since your homework was set trying to find an answer yourself, or have you just left your homework until the last minute?

Try:
SQL
SELECT EmpName, Dept, Salary FROM
       (SELECT  *, ROW_NUMBER() OVER (PARTITION BY Dept Order By Salary DESC) AS rn
          FROM    mytable4) x
WHERE   rn = 1
 
Share this answer
 
Comments
prabhu2210 8-Feb-15 0:57am    
it works fine but i need explanation abt SELECT *, ROW_NUMBER() OVER (PARTITION BY Dept Order By Salary DESC.. what is row_number()
OriginalGriff 8-Feb-15 2:17am    
Is Google not working where you are?
https://msdn.microsoft.com/en-us/library/ms186734.aspx
http://www.codeproject.com/Articles/308281/How-to-Use-ROW-NUMBER-to-Enumerate-and-Partition-R
Try this:
SQL
select  name, dept, salary from table1 t1
where salary = (
 select max(salary) from table1 t2 where t1.dept=t2.dept
)
 
Share this answer
 
select name,salary from tblname where salary in (select MAX(salary) from tblname)
 
Share this answer
 
v5

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900