The following solution is for getting 5th highest sal from emp table ,
SELECT TOP 1 sal FROM (
SELECT DISTINCT TOP 5 sal
FROM emp ORDER BY sal DESC) a
ORDER BY sal
General Syntax to Find Nth Sal, N is the variable
SELECT TOP 1 sal FROM (
SELECT DISTINCT TOP n sal FROM emp
ORDER BY sal DESC) a
ORDER BY sal
where n > 1
Note :-n is always greater than one
SELECT TOP 1 sal FROM (
SELECT DISTINCT TOP 5 sal
FROM emp ORDER BY sal DESC) a
ORDER BY sal
General Syntax to Find Nth Sal, N is the variable
SELECT TOP 1 sal FROM (
SELECT DISTINCT TOP n sal FROM emp
ORDER BY sal DESC) a
ORDER BY sal
where n > 1
Note :-n is always greater than one
No comments:
Post a Comment