Results 1 to 5 of 5

Thread: How to get the highest salary in each grade

  1. #1
    Join Date
    Nov 2002
    Posts
    19

    How to get the highest salary in each grade

    Table name: Employee

    Column Names: Emp_Code,Emp_name,Grade,Basic

    I want to execute an SQL that should give me the highest salary earned by an employees in each grade from the employee table?

    Like following:

    Emp_Code Emp_Name Grade Basic
    -------- -------- ----- -----
    AA0701 ALIS A 100000
    CE0101 CHRIST B 79500
    BJ0601 BOB C 50000
    FJ0012 FLORIN D 10000

    Thanks in advance

  2. #2
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    Try this

    select Emp_Code, Emp_Name, Grade , max(Basic)
    from Employee
    group by Emp_Code, Emp_Name, Grade

  3. #3
    Join Date
    Nov 2002
    Posts
    19
    Thanx for attending my Query and putting effort to reply it!

    I tried but didn't worked up! Gives all Emps. in all the grades with their salary. Can u suggest any other SQL please?

  4. #4
    Join Date
    Nov 2002
    Location
    New Jersey, USA
    Posts
    3,932
    If you wanted only the highest paid employee in each grade?

    select A.Emp_Code, A.Emp_Name, A.Grade , A.Basic
    from Employees A
    where exists
    (select * from Employees B
    Where A.Grade = B.Grade
    group by B.Grade
    having A.Basic = Max(B.Basic))

  5. #5
    Join Date
    Nov 2002
    Posts
    19

    Thumbs up

    Simply genious,
    It worked the way I wanted it!

    Thans alot for your precious advise.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •