I Have Employee table having column name as ID,SALARY
how to get second max salary from employee table with id
ex
ID SALARY
1 20000
7 37000
2 5000

Answer Posted / tusar

select distinct (a.sal),empno from emp a
where &N = (select count (distinct(b.sal))
from emp b where a.sal <= b.sal);

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you understand by integration services in sql server?

719


Can we linked SharePoint to a SQL database?

747


Can we join two tables without primary key?

804


What is extended stored procedures?

719


What is for xml in sql server?

686






What are the advantages of partitioning?

823


What is difference between oltp and olap?

783


What are types of subqueries?

749


Explain what are the database objects? : SQL Server Architecture

754


what are the different ways to return the rowcount of a table?

746


What is a subquery in a select query statement in ms sql server?

805


Which is better statement or preparedstatement?

696


what is the primary use of the model database? : Sql server administration

728


What is nested transaction?

764


if no size is defined while creating the database, what size will the database have? : Sql server administration

748