Saturday, May 14, 2011

second largest salary without using TOP

SELECT Emp_Name,Emp_Salary FROM Employee e1WHERE
 2 = (SELECT COUNT(DISTINCT (e2.Emp_Salary))FROM Employee e2 WHERE e2.Emp_Salary >= e1.Emp_Salary)



select b.Emp_Salary from
(
(select distinct Emp_Salary from employee) a,select distinct Emp_Salary from employee) bwhere a.Emp_Salary>b.Emp_Salarygroup by b.Emp_Salaryhaving

count(b.Emp_Salary)=2

No comments:

Post a Comment