sql语句中in not in和exists not exists区别和用法

不理解in与exists改用在 什么地方,请各位大神赐教。。。。。。

in 和 not in
select * form 学生表 where 学生ID in(表示在...中,not in表示不在...中) (1,2,3,45,)(这句话就是说从学生表中找学生ID在1,2,3,45或不在这里面的学生信息)

exists 和 not exists
一般用于表是否存在,上面说的很清楚了

一个是一个范围内有,一个是查询是否存在

看下用法就知道区别了。not in 和not exists正好与in和exists相反。

 --后面的查询记录存在不存在
if exists (select * from sysobjects where name = '表')
 drop table 表

--id字段在不在后面的(1,3,5)集合范围内
select * from 表 where id in (1,3,5)