i have a complicated problem

  • i have 3 tables, table names are emp,dept there schema is as under emp=empcode,empname,salary,deptcode now i want to have result i want to get max(salary) i want to know the salary,name,departname means i want to know max(salary) department wise select empname,deptname,max(salary) from emp em but it shows all the records because empname is included in the group clause now what should i do?

    <a href="http://www.websolsoftware.com"> For IT jobs click here</a>

    *Sukhoi*[font="Arial Narrow"][/font]

  • Not sure what you need you message seems chopped. Weird it was chopped when viewed from the house. Did the last edited remark go away?

  • Are you looking for something like this?

    SELECT d.DeptName, e.EmpName, e.Salary

    FROM Employees e JOIN Departments d ON e.DeptCode = d.DeptCode

    JOIN

    (SELECT DeptCode, MAX(Salary) Salary

     FROM Employees

     GROUP BY DeptCode) x ON e.DeptCode = x.DeptCode AND e.Salary = x.Salary



    --Jonathan

  • Yes! Now you can change history without notice.

    Isn't that brilliant?

    --
    Frank Kalis
    Microsoft SQL Server MVP
    Webmaster: http://www.insidesql.org/blogs
    My blog: http://www.insidesql.org/blogs/frankkalis/[/url]

  • thanks jonathan, i was asked this query in an interview and i couldn't ans i was applying for the post of DBA hehe

    <a href="http://www.websolsoftware.com"> For IT jobs click here</a>

    *Sukhoi*[font="Arial Narrow"][/font]

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply