Find Out lowest salary
We want to find lowest fourth salary.
- select top 1 salary from t1 where salary in( select distinct top 4 salary from t1 order by salary asc) order by salary desc
Step 1:
If you wand second, third, fourth, nth lowest salary.
For example I want to find fourth lowest salary by this query we found out four lowest salary.
- select distinct top 4 salary from t1 order by salary asc
Step 2:
Now we find top 1 highest salary form step-1 query by reverse in desc order.
- select top 1 salary from t1 where salary in
- (
- select distinct top 4 salary from t1 order by salary asc
- )
- order by salary desc
You can find nth higest salary by replacing number like:
- select top 1 salary from t1 where salary in
- (
- select distinct top n salary from t1 order by salary asc
- )
- order by salary desc
Just try this, I hope it will help you.