Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2004
    Location
    Mars
    Posts
    137

    Unanswered: Help with group by clause

    Hi

    My table structure

    Code:
    SEQ_ID
    EMP_ID
    DEP_ID
    SAL
    I want to get the EMPLOYEE with the highest salary in a particular department
    Code:
    select dep_id, max(sal) FROM tbl_name GROUP BY dep_id
    will give me the maximum salary for departments but how to get the emp_id also..?
    Last edited by Sudar; 12-22-05 at 02:37.
    Sudar

    --
    My Blog

  2. #2
    Join Date
    Jul 2004
    Location
    Mars
    Posts
    137

    Thumbs up

    Ok I found out the query by myself. Here is it.


    Code:
    SELECT * FROM tbl_name WHERE (dept_id, sal) IN (SELECT dep_id, MAX(sal) FROM tbl_name GROUP BY dept_id)
    Sudar

    --
    My Blog

Posting Permissions

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