Inner Query



How to find nth heights salary in employee record?
Or
How to find heights value as required?
Or
How to find 10th heights value as given entity?
Or
How to Use Inner Query?
Or
How to use while more than ones?


Answer-1:

SELECT DISTINCT(A.EMP_SALARY) FROM EMPLOYEE A
WHERE &SALARY = (SELECT COUNT(DISTINCT(B.EMP_SALARY)) FROM EMPLOYEE B
WHERE A.EMP_SALARY<=B.EMP_SALARY);

Inner Query :
SELECT COUNT(DISTINCT(B.EMP_SALARY)) FROM EMPLOYEE B WHERE A.EMP_SALARY<=B.EMP_SALARY

The query you have mentioned is a co-related subquery which means for each record from outerquery,
the inner query will be executed and returns its output.

Consider you want to display 3rd highest salary, so &SALARY = 10

Inner query will return the number of distinct salary records in the table which matches A.emp_salary <= B.emp_salary. If the count matches with 10 then your query will return that salary record.

No comments:

Post a Comment

Popular Posts