write the query for find the top 2 highest salary in sql
server
Answers were Sorted based on User's Feedback
Answer / saritha
select distinct top 2 salary from EMP order by salary desc
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / adiseshu
select * from (
select dense_rank() over (order by salary desc) rno,* from
employees ) as a where rno in(1,2)
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / mohan c v
select min(salary) from
(select top 2 salary from phani order by salary desc) as a
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / tanay chaudhary
select * from(select emp.*,Dense_Rank() over(order by salary desc) as ranking from emp)as e where e.ranking in(1,2)
//emp=table name
//salary=column name
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / santosh kumar
select Top 1 salary from ( select top 2 salary from
emp_table order by salary desc)temptable order by salary
desc.
Is This Answer Correct ? | 13 Yes | 14 No |
Answer / santosh kumar
select Top 1 salary from ( select top 2 salary from
emp_table order by salary desc)temptable order by salary
asc.
Is This Answer Correct ? | 11 Yes | 12 No |
SELECT TOP 1 salary FROM (SELECT DISTINCT TOP 2 salary FROM
employee ORDER BY salary DESC) a ORDER BY salary
Is This Answer Correct ? | 3 Yes | 4 No |
Answer / neeraj sharma
select ename,sal from emp where rownum<=3 order by sal desc
Note:- every table has rownum column but it is hidden by
default you can see it by this
select rownum from your_table_name
Is This Answer Correct ? | 3 Yes | 4 No |
Answer / vijayalaxmi m khot
select max(sal) from emp where sal=(select max(sal) from emp
where sal<(select max(sal) from emp));
Is This Answer Correct ? | 1 Yes | 3 No |
Answer / shahid
select * from(select * from Employee order by salary desc) where rowNum<3
Is This Answer Correct ? | 0 Yes | 3 No |
what is the out put of below queries? a. select * from Emp where null = null; b. select * from Emp where 1=1;
How to use column default values in insert statements in ms sql server?
What are the different types of replication you can set up in sql server?
How to start and end transact-sql statements?
how to find number of columns in a table in sql server 2000 and 2005 also
What are ddl (data definition language) statements for tables in ms sql server?
What is cursor in ms sql server?
what is syntex second or third highest salary. thanks & Regards Dhirendra sinha
What is a table called, if it does not have neither Cluster nor Non-cluster Index?
Difference between writing SQL query and stored procedure ?
15 Answers Cognizant, Infosys, TCS, Veritas,
There is a trigger defined for INSERT operations on a table, in an OLTP system. The trigger is written to instantiate a COM object and pass the newly insterted rows to it for some custom processing. What do you think of this implementation? Can this be implemented better?
How to read 2nd highest sal from EMP table?