Difference between EXISTS and IN in SQL?

前端 未结 21 1520
执笔经年
执笔经年 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:29

    IN:

    • Works on List result set
    • Doesn’t work on subqueries resulting in Virtual tables with multiple columns
    • Compares every value in the result list
    • Performance is comparatively SLOW for larger result set of subquery

    EXISTS:

    • Works on Virtual tables
    • Is used with co-related queries
    • Exits comparison when match is found
    • Performance is comparatively FAST for larger result set of subquery

提交回复
热议问题