Difference between EXISTS and IN in SQL?

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

    The Exists keyword evaluates true or false, but IN keyword compare all value in the corresponding sub query column. Another one Select 1 can be use with Exists command. Example:

    SELECT * FROM Temp1 where exists(select 1 from Temp2 where conditions...)
    

    But IN is less efficient so Exists faster.

提交回复
热议问题