Sunday, July 27, 2008

HOW TOGET SECOND MINIMUM VALUES FROM TABLE IF VALUE HAVE MULTIPLE OCCURENCES.

I have build this query to get the 2nd minimum amount (salary) of employees no matter how much occurrences they have. I want to retrieve each occurrence of 2nd minimum amount. The following query gives me my desired result.


Select amount
From table2
where amount = ( Select distinct top 1 amount
from (Select top 2 amount
from table2
order by amount asc) a
order by amount desc )

No comments: