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.

Answer Posted / 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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between mysql and sql server?

467


Explain the use of keyword with encryption. Create a store procedure with encryption?

537


Find first and last day of current month in sql server

595


Explain “row_number()” in sql server with an example?

518


Do you know the isolation level that sql server support?

522






What is raid? : SQL Server Architecture

589


How to use "if ... Else if ... Else ..." Statement structures in ms sql server?

535


What is the purpose of forms?

488


What is lock escalation? : sql server database administration

592


How to write an inner join with the where clause in ms sql server?

548


What is a group function explain with an example?

519


What is the significance of null value and why should we avoid permitting null values?

530


What is difference between index and primary key?

578


What is BCP? When does it used in sql server 2012?

576


What is trigger and different types of Triggers?

569