Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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 make conditional sum in ssrs?

173


What is BCNF? How is it better than 2NF & 3NF?

963


Tell me what is sql profiler?

982


What are the limitations/drawbacks or ssrs 2008 r2?

129


What are built in functions?

954


What is the minimum and maximum number of partitions required for a measure group? : sql server analysis services, ssas

1006


 Explain what is sql override for a source taLle in a mapping?

947


what purpose does the model database serve? : Sql server database administration

924


How sql server executes a statement with nested subqueries?

962


Suppose we have a table "MyTable" containing 10 rows, what query should be executed to update the odd rows "Salary" as 9000?

934


How can I create a new template for import ? : sql server management studio

1025


How can you find out which stored procedures are recompiling?

883


Where do we use trace frag?

971


What are the differences between clustered and non-clustered index?

956


What are the different types of backups avaialabe in sql server 2005?

972