SQL Server Performance

Urgent Query

Discussion in 'Getting Started' started by SATISD9X, Oct 16, 2007.

  1. SATISD9X New Member

    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?
  2. thomas New Member

  3. ranjitjain New Member

    Is this your interview question?
  4. Jeena New Member

    Try this query
    select e.empname,s.empsal,d.deptname from emp e,empsal s,dept d order by empsal
    Thanks
    Jeena
  5. Greg Larsen New Member

    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

Share This Page