Home / CSE / SQL Basics :: Discussion

Discussion :: SQL Basics

  1. Table Employee has 10 records. It has a non-NULL SALARY column which is also UNIQUE.
    The SQL statement
    SELECT COUNT(*) FROM Employee WHERE SALARY > ANY (SELECT SALARY FROM EMPLOYEE);
    prints

  2. A.

     10

    B.

     9

    C.

     5

    D.

     0

    View Answer

    Workspace

    Answer : Option B

    Explanation :

    ANY compares a value with each of the values in a list or results from a query and evaluates to true if the result of an inner query contains at least one row. ANY must be preceded by comparison operators(=, >, <, <=, >=, <>).

    Employee table has 10 records and each value in non-NULL SALARY column is unique i.e different. So, in that 10 records one of the record will be minimum which cannot be greater than any nine value of the salary column. Hence the condition
    WHERE SALARY > ANY (SELECT SALARY FROM employee)
    will be true nine times. So, the COUNT(*) outputs 9.


Be The First To Comment