For past 15 days I am actively participating in the discussion forums of dotnetspider. Yesterday there was a question relating to SQL Server which seems to be asked in interviews very often. i.e., How to find out the 2nd highest salary of an employee?
Thought I would give out an sample for those who are yet to find an answer for this. For that purpose I have given a table structure with few sample records inserted to it.
-- Table Structure
Create table employee
-- Populate Sample Records
Insert into employee values ('Vadivel', 80000)
Insert into employee values ('Vel', 70000)
Insert into employee values ('xxx', 40000)
Insert into employee values ('Sneha', 60000)
Select top 1 [Name], Sal from
Select Top 2 [Name], Sal from employee order by Sal Desc
) AS A1 Order by Sal
Technorati tags: SQL, Databases, SQL Server, SQL Server 2005