No wonder everyone keeps failing that course ;)SELECT TOP 2 EmpId, Salary FROM (SELECT TOP 3 EmpId, Salary FROM table ORDER BY Salary desc) AS xxx ORDER BY Salary ascbut actually, given these top 6 emp/saleries, 2nd and 3rd highest salary is 90 and 95 (emp6 and emp4/5)What do you want returned in this case?emp1 100emp2 100emp3 100emp4 95emp5 95emp6 90Here is another couple ways to rank the employees by salary:set nocount ondeclare @emp table (empid int identity(1,1), salary int)insert @emp (salary)select 100 union allselect 100 union allselect 100 union allselect 95 union allselect 95 union allselect 90 union allselect 90 union allselect 89 union allselect 88 union allselect 88select a.empid ,a.EmpRankBySal ,a.salaryrank ,b.salaryfrom ( select empid ,EmpRankBySal = (select count(*) from @emp where salary > a.salary) + 1 ,salaryRank = (select count(distinct salary) from @emp where salary > a.salary) + 1 from @emp a ) aJOIN @emp b ON a.empid = b.empid--where EmpRankBySal IN (2,3)--Where salaryrank in (2,3)order by salaryrank
Be One with the OptimizerTG