SQL in/not in/exists/not exists

Posted 北美大地

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了SQL in/not in/exists/not exists相关的知识,希望对你有一定的参考价值。

一、IN 、NOT IN 

  IN 操作符允许在 WHERE 子句中规定多个值。column_name中取值为value1 、value2....的数据会被筛选出来。

(1)in的两种应用场景

select name from student where name in(zhang,wang,zhao);
select * from A where cc in(select cc from B) 

(2)in 与 “=”的区别:

select name from student where name in(zhang,wang,zhao);
select name from student where name=‘zhang‘ or name=‘wang‘ or name=‘zhao‘

*IN 和 NOT IN并不是针对索引的,因此查询会消耗大量时间

二、EXISTX / NOT EXISTS 

以上是关于SQL in/not in/exists/not exists的主要内容,如果未能解决你的问题,请参考以下文章