Examveda
Examveda

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

A. 10

B. 9

C. 5

D. 0

Answer: Option B

Solution(By Examveda Team)

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.


This Question Belongs to SQL >> Sql Miscellaneous

Join The Discussion

Comments ( 7 )

  1. Nishar_Kn
    Nishar_Kn :
    2 years ago

    If i can't see your comments,I have doubt on it always.😄

  2. Rose Jamal
    Rose Jamal :
    2 years ago

    sorry but what is happen if table one have 4 records but table 2 have 6 records

  3. Swati Kumari
    Swati Kumari :
    4 years ago

    Suppose we have a table with 10 records
    30
    40
    50
    20
    10
    2
    8
    9
    7
    5
    The smallest one is 2 so how we get 2 after comparing it with other 9 numbers so counting of comparison is 9 and the 10th number is 2.. So ans is 9 we have to count the number of comparison..

  4. Sangareswari Ramadoss
    Sangareswari Ramadoss :
    5 years ago

    I think counting numbers 0 to 9

  5. Piyush Jain
    Piyush Jain :
    6 years ago

    Suppose there are 10 salary
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    Now any will compare all salary. But 1 is always min from all of these. Thats why we will get 9 large only

  6. Mine Picks
    Mine Picks :
    6 years ago

    am not getting it!
    can u explain it in simple words!

  7. Mine Picks
    Mine Picks :
    6 years ago

    am not getting it!
    can u explain it in simple words!

Related Questions on Sql Miscellaneous