I need a query for the following Tables [Emp] [Dept] [EmpDept] [EmpSalary] ===== ===== ======== ========= EmpID DeptID EmpID EmpID EmpNM DeptNm DeptID EmpSalary Find a query to find out all the employees who had the maximum salary (if more than one have same max salary show each of them) for each Department?
Try this query select e.empname,s.empsal,d.deptname from emp e,empsal s,dept d order by empsal Thanks Jeena
Need to have a subquery in your where statement something like this:create table y(i int, j int)insert into y values (1,1)insert into y values (2,2)insert into y values (3,1)insert into y values (1,1)insert into y values (2,2)insert into y values (1,2)insert into y values (5,3)select * from y a where i = (select max(i) from y where a.j = j ) and j = (select top 1 j from y where a.j = j) drop table y