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 significance of null value and why should we avoid permitting null values?

530


What is a deadlock and what is a live lock?

571


What is a dataset and what are the different types of datasets?

93


How many types of built in functions are there in sql server 2012?

488


What is 4nf in normalization form?

562






Define constraints and give an example of their use?

559


please differentiate between delete and truncate?

558


How to provide column names in insert statements in ms sql server?

600


what are constraints? : Sql server database administration

517


What is the difference between SQL notification and SQL invalidation?

585


What are the properties of sub-query?

577


how to trace the traffic hitting a sql server? : Sql server database administration

1123


In which tcp/ip port does sql server run? Can it be changed?

540


how to invoke a trigger on demand? : Sql server database administration

563


What is dynamic cursor in SQL SERVER?

559