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
Answer / asimananda
SELECT MAX(SAL) FROM EMP WHERE SAL < ( SELECT MAX(SAL) FROM
EMP )
Is This Answer Correct ? | 7 Yes | 2 No |
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 |
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 |
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 |
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 |
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 |
What is the impact on other user sessions when creating indexes?
If we delete pack Spec what will be the status of pack Body ?
Why I have to use stored procedures?
What are the four main query statements?
How to insert a new row into a table with "insert into" statements in ms sql server?
How to choose all records from the table?
Tell me what is the significance of null value and why should we avoid permitting null values?
How do you connect 100 files as a flat file sources in one package of SSIS?
how to find number of columns in a table in sql server 2000 and 2005 also
Can you explain what is indexed view? How to create it?
What is the difference between for trigger and after trigger?
Explain the disadvantages of cursors?