Click here to Skip to main content
15,886,137 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have written following line of query in sql

SQL
select did Deptid,MAX(salary)'Highest Salary' from Empmaster e,Deptmaster d
where e.did=d.deptid
group by did



this gives me output as

110 100000.00
120 65000.00
130 50000.00
140 45000.00


but what if i want to display a name of employee with the same query .
what i need to write extra in the abouve query.

Please help me to solve this query
Thank in advance
Posted

This way...
SQL
select Deptid,Employeename,salary from
(
    select row_number() over(order by e.did,salary desc) as srno, 
    did Deptid,e.EmployeeName,salary
    from Empmaster e
    JOIN Deptmaster d on e.did=d.deptid
    group by did,e.EmployeeName
) as temp
where SrNo=1

Happy Coding!
:)
 
Share this answer
 
u cn try below query

SQL
select did Deptid,e.EmployeeName,MAX(salary)'Highest Salary' 
from Empmaster e
JOIN Deptmaster d on e.did=d.deptid
group by did,e.EmployeeName



vote if it helps u.
:)
 
Share this answer
 
Comments
fjdiewornncalwe 30-Jan-13 10:08am    
My 1. This code won't even validate in management studio.

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