Difference between IN and ANY operators in SQL

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

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

10条回答
  •  盖世英雄少女心
    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.

提交回复
热议问题