Monday 8 July 2013

To Find 2nd and 3rd highest Salary


SELECT sal FROM employee WHERE sal = (SELECT DISTINCT(sal) 
  FROM employee as e1   WHERE (n) = (SELECT COUNT(DISTINCT(sal)) 
  FROM employee as e2  WHERE e1.sal <= e2.sal))

change (n) by 1,2 or 3 or 4 to get second,third or fourth highest salary.

No comments:

Post a Comment