what is syntex second or third highest salary.
thanks & Regards
Dhirendra sinha
Answers were Sorted based on User's Feedback
Answer / sagar dhande
select top 2(salary) from (select top 3 (salary) from
dbo.employee order by salary desc)
order by salary
Is This Answer Correct ? | 3 Yes | 1 No |
Answer / praveen singh
select min(salary) from salary where salary in(select top 3
salary from salary order by salary desc)
Is This Answer Correct ? | 3 Yes | 2 No |
Answer / satish
select max(sal) from emp e1 where 1< (select count(distinct sal) from emp e2 where e1.sal <= e2.sal)
To make it generic if u want N'th highest salary;
select max(sal) from emp e1 where (N-1)< (select count(distinct sal) from emp e2 where e1.sal <= e2.sal)
And to get the N'th min sal :
select min(sal) from emp e1 where (N-1)< (select count(distinct sal) from emp e2 where e1.sal >= e2.sal)
Is This Answer Correct ? | 1 Yes | 0 No |
with Topsal (EmpID,Ename,Sal,Dno,Topsal) as
(select *,row_number() over(order by sal) Topsal from emp)
select top 2 EmpID,Ename,Sal,Dno from Topsal order by sal desc
Is This Answer Correct ? | 1 Yes | 0 No |
Answer / vikas kant
---To get 2nd highest salary----
select Top 1 salary from Emp where marks in(select top 2
salary from Emp order by salary desc)
---To get 3rd highest salary----
select Top 1 salary from Emp where marks in(select top 3
salary from Emp order by salary desc)
Regards Vikas Kant
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / anil tiwari
select Top2(salery)from (select Top3 (salery) from tab1
order by salery DESC)order by salery.
Is This Answer Correct ? | 0 Yes | 0 No |
Answer / dipti saxena
select sal,rownum from (select sal from emp
order by sal desc)
where rownum<=3
MINUS
select sal,rownum from (select sal from emp
order by sal desc)
where rownum<=1
Is This Answer Correct ? | 0 Yes | 4 No |
how you can list all the tables in a database?
How sql server executes a statement with nested subqueries?
A left outer join B B right outer join A gives the same result then what is the use of two?
How to execute function in stored procedure sql server?
How do you debug a procedure in sql server?
after migrating the dts packg to ssis by using migrtn wizrd in 2005. iam not able to open ssis pack and getting error. what r those errors? how to resolve?
what is victor class
How many types of indexes are there in SQL Server?
6 Answers CarrizalSoft Technologies, United Healthcare,
Explain about local stored procedure?
What protocol does sql server use?
What is the differecne between equi-join and inner-join and natural join..Is there any difference or all are same?
How should i optimize the time for execution of stored procedure having single input and many output from the different tables?