Max 3

  • Hi i want to select 3 highest Salary in a company.

    Suggest me a sql query..

    my table is

    Emp_ID Emp_name Salary

    1 Ram 12000

    2 Sham 16000

    3 Sharma 25000

    4 Daniel 10000

    5 Sonia 24000

    6 Rohit 17000

  • Hi,

    try this

    select top 3 emp_id,Emp_name, salary from MyTable

    order by salary desc

    ARUN SAS

  • select top 3 sal from order by sal

  • Finding Nth Position without TOP :

    ;WITH Salary

    AS (SELECT Emp_ID,Emp_Name,Salary,DENSE_RANK() OVER(ORDER BY Salary DESC ) 'Rank' FROM MyTable)

    -- Finding Max 3 Salaries

    SELECT * FROM Salary WHERE Rank <=3

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

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