Multiple choice

Consider the following database table

Table Name- EM ||||| |---|---|---|---| |empid|deptno|Salary|city| |011|501|20000|Mumbai| |012|502|15000|Gurgaun| |013|503|24000|Delhi| |014|504|30000|Lucknow|

Find the details of employees earning the second highest salary.

  1. SELECT COUNT(DISTINCT SAL) FROM EMP E WHERE SAL>E.SAL

  2. SELECT MAX(DISTINCT SAL) FROM EMP E WHERE SAL>E.SAL

  3. SELECT * FROM EMP E WHERE 1=(SELECT COUNT(DISTINCT SAL) FROM EMP WHERE SAL>E.SAL)

  4. SELECT * FROM EMP E WHERE 0=(SELECT COUNT(DISTINCT SAL) FROM EMP WHERE SAL>E.SAL)

  5. None of the above

Reveal answer Fill a bubble to check yourself
C Correct answer
Explanation

This is the correct query as we need second highest salary so we need to query as the salary less than the first employee.