码迷,mamicode.com
首页 > 数据库 > 详细

SQL in/not in/exists/not exists

时间:2020-01-10 18:47:02      阅读:76      评论:0      收藏:0      [点我收藏+]

标签:sql   区别   round   from   sele   back   col   div   name   

一、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

标签:sql   区别   round   from   sele   back   col   div   name   

原文地址:https://www.cnblogs.com/liaoliao51/p/12177550.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!