Find 2nd Highest salery in emp table

Select* from emp where &n=
select * count from emp where (salery >=emp.salery)


Enter n value 2


These query is correct or not. Tell me any other methods.

Answers were Sorted based on User's Feedback



Find 2nd Highest salery in emp table Select* from emp where &n= select * count from emp whe..

Answer / asimananda

SELECT MAX(SAL) FROM EMP WHERE SAL < ( SELECT MAX(SAL) FROM
EMP )

Is This Answer Correct ?    7 Yes 2 No

Find 2nd Highest salery in emp table Select* from emp where &n= select * count from emp whe..

Answer / kb

select top 1 * from emp
where sal < (select max(sal)from emp)
order by sal desc

Is This Answer Correct ?    3 Yes 0 No

Find 2nd Highest salery in emp table Select* from emp where &n= select * count from emp whe..

Answer / lince

select top 1 * from (select distinct top 2 * from emp order by sal desc)t order by sal asc

Is This Answer Correct ?    1 Yes 0 No

Find 2nd Highest salery in emp table Select* from emp where &n= select * count from emp whe..

Answer / r.rajivgandhi

Select max(salary) from emp where salary <(select max
(salary) from emp)

These Query is correct.Try It

Is This Answer Correct ?    0 Yes 0 No

Find 2nd Highest salery in emp table Select* from emp where &n= select * count from emp whe..

Answer / madhu sudhan g

Hii lets consider the table Salary having EMPNO,EMPSal columns
to find the 2nd higest salary

;WITH CTE(Sal,Row)
AS
(
select EMPSal,ROW_NUMBER() OVER(ORDER BY EMPSal) as Row from Salary
)
select sal as Salary from CTE where Row=2

Is This Answer Correct ?    0 Yes 0 No

Find 2nd Highest salery in emp table Select* from emp where &n= select * count from emp whe..

Answer / ramu

by using sub quries we can do
select * from emp where sal=select max(sal) from emp where
sal<select max(sal) from emp;

Is This Answer Correct ?    1 Yes 2 No

Post New Answer

More SQL Server Interview Questions

Tell me the phases a transaction has to undergo?

0 Answers  


What is the difference between functions and stored procedures?

0 Answers   Accenture,


what is a stored procedure and trigger?

3 Answers  


What are the different types of triggers in SQL SERVER?

0 Answers  


Can XML be used to access data?

2 Answers  






How can we remove orphan records from a table?

0 Answers  


Consider a table with 8 rows 4 rows contains value 0 and 4 rows contains value 1.Now write a single update query to make all 0's as 1 and all 1's as 0

7 Answers   PMAM IT Services, TCS,


What is RMS migrations?

0 Answers   Satyam,


How to create a simple user defined function in ms sql server?

0 Answers  


Which is better in performance - CONSTRAINT or TRIGGER over a column which restricts say an input of particular value in a column of a table?

3 Answers   Accenture,


What is database dimension? : sql server analysis services, ssas

0 Answers  


How to update muliple row in single query?

0 Answers   MCN Solutions,


Categories