how to find the second highest salary from emp table?

Answer Posted / chitti

Hi Viewers here is the simple query to find the highest
salary:-

1)Highest five salaries:-

select top 5 salary from employee order by salary desc

2)Highest 5th salary:-

select top 1 salary from(select top 5 salary from
employee order by salary desc) temp1 order by salary asc

3)Highest 4th salary:-

select top 1 salary from (select top 4 salary from
employee order by salary desc) temp1 order by salary asc

4)Highest 3rd salary:-

select top 1 salary from (select top 3 salary from
employee order by salary desc) temp1 order by salary asc

5)Highest 2nd salary:-

select top 1 salary from(select top 2 salary from
employee order by salary desc) temp1 order by salary asc

6)Highest 1st salary or highest salary:-

select max(salary) from employee

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Is it possible to create the following trigger: before or after update trigger for each row?

718


How does sql store data?

481


what does it mean to have quoted_identifier on? : Sql dba

674


What is autocommit sql?

538


What is trigger with example?

562






Explain the uses of control file.

613


Is null operator in sql?

604


How to get list of all tables from a database?

623


Can pl sql procedure have a return statement?

548


Table 1: col1 Timestamp ---------------- 01-mar-2012 11:12:46 Table 2: col2 Timestamp -------------------- 01-mar-2012 11:12:10 01-mar-2012 11:11:23 Write a query to display a row with table2 col2 value less than tabl1 col1 value. Maximum timestamp value previous to table1 col1 value. Display a result as: Col1 col2 ----- ----- 01-mar-2012 11:12:46 01-mar-2012 11:12:10

1720


What is a table partition?

591


Is it possible to pass parameters to triggers?

571


What steps server process has to take to execute an update statement?

506


Why we use join in sql?

526


What is a dynamic query?

569