Difference between IN and ANY operators in SQL

后端 未结 10 1766
無奈伤痛
無奈伤痛 2020-12-23 11:14

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

相关标签:
10条回答
  • 2020-12-23 12:04

    The ANY and ALL operators are used with a WHERE or HAVING clause.

    The ANY operator returns true if any of the subquery values meet the condition.

    The ALL operator returns true if all of the subquery values meet the condition.

    0 讨论(0)
  • 2020-12-23 12:07

    Maybe for better understanding, these two conditions are equivalent. It's a matter of taste which one you use (provided the RDBMS supports both of them)

    ... WHERE x IN (SELECT Y FROM THE_TABLE)  
    ... WHERE x =ANY (SELECT Y FROM THE_TABLE) 
    

    and these also

    ... WHERE x NOT IN (SELECT Y FROM THE_TABLE) 
    ... WHERE x <>ALL (SELECT Y FROM THE_TABLE) 
    

    Actually my personal habit is to use IN for list expression (like WHERE x IN (2,4,6,8) and =ANY, resp. <>ALL for sub-queries.

    0 讨论(0)
  • 2020-12-23 12:08

    (in) is a special kind of operator which is use to pick value one by one from list of values which we have specified.while (any) is use with where clause

    0 讨论(0)
  • 2020-12-23 12:16

    When we are comparing any column value using "IN" some set say {value1,value2 ...} then the column value must be present in the set but in case of ANY we compare like this:

    col.value > ANY ({value1,value2,...})
    

    then the value must be greater than any one of the set value.

    in case of "ALL"

    col.value> ALL({value1,value2,...})
    

    the value must be greater than all the values in the set.

    Refer to the following images for better understanding:

    • this is my database employee
    • all query
    • any query
    • in query
    0 讨论(0)
提交回复
热议问题