actually one modification here , your first table should have one alias also like below example.: select distinct salary from ( select salary,dense_rank() over(order by salary desc) as dr from employee ) A where dr=n but very nice explanation , thanks, SR