How to find the second largest salary in the emp database and
also How to find 3rd,4th and so on ........ in the emp database

plz mail the answer @ mak2786@gmail.com

Answer Posted / sandee saxena

-- Create table #temp
-- (
-- Emp_id int identity(1,1),
-- Emp_Name varchar (100) ,
-- Emp_Salary int
-- )

--
-- Insert into #Temp (Emp_Name, Emp_Salary) values
('kunal', '2000')
-- Insert into #Temp (Emp_Name, Emp_Salary) values
('aditya', '5000')
-- Insert into #Temp (Emp_Name, Emp_Salary) values
('abhishek', '6000')
-- Insert into #Temp (Emp_Name, Emp_Salary) values
('kailash', '5000')
-- Insert into #Temp (Emp_Name, Emp_Salary) values
('rohit', '8000')
-- Insert into #Temp (Emp_Name, Emp_Salary) values
('rakesh', '3000')

Select a.* From #temp a,
(Select Max(a.Emp_salary)Emp_Salary From #temp a,
(Select Max(x.Emp_salary)Emp_Salary From #temp a,
(Select a.* From #temp a,(Select Max (Emp_Salary)Emp_Salary
From #Temp) b
Where a.Emp_Salary < b.Emp_Salary ) x ) y
where a.Emp_Salary < y.Emp_Salary)Z
where a.Emp_Salary = z.Emp_Salary

Is This Answer Correct ?    0 Yes 1 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the use of RDBMS?

591


What options are available to audit login activity? : sql server security

635


List the data types available in mssql?

530


What do you understand by recursive stored procedure?

522


Explain use of expression builder.

567






Is it possible in sql table to have more than one foreign key?

614


How to find out what is the default collation in a database?

632


What is normalization 1nf 2nf 3nf?

631


What are commonly used odbc functions in php?

542


What is shared lock?

493


How we can refresh the view?

596


What is raid and what are different types of raid levels?

594


How to change a login name in ms sql server?

562


How to reaname table name without using sp_Rename in sql server..?

530


How much memory that we are using in Logshipping Concept?

1368