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

How to create and drop temp table in sql server?

593


List the different index configurations possible for a table?

521


What are the different types of backups that exist?

691


How to grant a permission in ms sql server using "grant execute" statements?

571


Can we do dml on views?

559






You have to store user responses of ‘yes’ and ‘no’ what kind of data type is best suited for this task?

538


What is a recursive stored procedure in sql server?

578


What are the different types of collation sensitivity in sql server?

594


You want to implement the one-to-one relationship while designing tables. How would you do it?

539


List the advantages of using stored procedures?

565


What is the purpose of optimization?

550


Can we write ddl in trigger?

501


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

601


What is sql server programming?

559


Can I work with several databases simultaneously? : sql server management studio

573