sqloperatorsany

Difference between IN and ANY operators in SQL


What is the difference between IN and ANY operators in SQL?


Solution

  • SQL>
    SQL> -- Use the ANY operator in a WHERE clause to compare a value with any of the values in a list.
    SQL>
    

    SQL> -- You must place an =, <>, <, >, <=, or >= operator before ANY.

    SQL> SELECT *
      2  FROM employee
      3  WHERE salary > ANY (2000, 3000, 4000);
    

    For In Operator

    SQL> -- Use the IN operator in a WHERE clause to compare a value with any of the values in a list.
    SQL> SELECT *
      2  FROM employee
      3  WHERE salary IN (2000, 3000, 4000);
    

    But with the IN operator you cannot use =, <>, <, >, <=, or >=