common but tricky queries
I will be covering some of the common but tricky queries like:- (i) Finding the nth highest salary of an employee. (ii) Finding TOP X records from each group. (iii) Deleting duplicate rows from a table. NOTE : All the SQL mentioned in this article has been tested under SQL Server 2005. (i) Finding the nth highest salary of an employee. Create a table named Employee_Test and insert some test data as:- CREATE TABLE Employee_Test ( Emp_ID INT Identity, Emp_name Varchar( 100 ), Emp_Sal Decimal ( 10 , 2 ) ) INSERT INTO Employee_Test VALUES ( ' Anees' , 1000 ); INSERT INTO Employee_Test VALUES ( ' Rick' , 1200 ); INSERT INTO Employee_Test VALUES ( ' John' , 1100 ); INSERT INTO Employee_Test VALUES ( ' Stephen' , 1300 ); INSERT INTO Employee_Test VALUES ( ' Maria' , 1400 ); It is very easy to find the highest salary as:- -- Highest Salary select max(Emp_Sal) from Employee_Test Now, if you are asked to find the 3rd highest sala...