Difference between EXISTS and IN in SQL?

前端 未结 21 1810
执笔经年
执笔经年 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条回答
  •  猫巷女王i
    2020-11-22 17:38

    Difference lies here:

    select * 
    from abcTable
    where exists (select null)
    

    Above query will return all the records while below one would return empty.

    select *
    from abcTable
    where abcTable_ID in (select null)
    

    Give it a try and observe the output.

提交回复
热议问题