Difference between EXISTS and IN in SQL?

前端 未结 21 1530
执笔经年
执笔经年 2020-11-22 16:50

What is the difference between the EXISTS and IN clause in SQL?

When should we use EXISTS, and when should we use IN

21条回答
  •  粉色の甜心
    2020-11-22 17:12

    Which one is faster depends on the number of queries fetched by the inner query:

    • When your inner query fetching thousand of rows then EXIST would be better choice
    • When your inner query fetching few rows, then IN will be faster

    EXIST evaluate on true or false but IN compare multiple value. When you don't know the record is exist or not, your should choose EXIST

提交回复
热议问题