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
How to make conditional sum in ssrs?
What is BCNF? How is it better than 2NF & 3NF?
Tell me what is sql profiler?
What are the limitations/drawbacks or ssrs 2008 r2?
What are built in functions?
What is the minimum and maximum number of partitions required for a measure group? : sql server analysis services, ssas
 Explain what is sql override for a source taLle in a mapping?
what purpose does the model database serve? : Sql server database administration
How sql server executes a statement with nested subqueries?
Suppose we have a table "MyTable" containing 10 rows, what query should be executed to update the odd rows "Salary" as 9000?
How can I create a new template for import ? : sql server management studio
How can you find out which stored procedures are recompiling?
Where do we use trace frag?
What are the differences between clustered and non-clustered index?
What are the different types of backups avaialabe in sql server 2005?