exists 和 not exists 的用法

1 我们总是习惯了用in 和 not in 但是这样有时会会很影响性能,下面来看看用exists 和 not exists 的使用方法

首先新建两张表 a 和 b

 

select a.* from a where exists (select * from b where a.value = b.value)

select a.* from a where exists (select * from b where a.value = b.value)

我们看到 只要exists 里面 返回有数据 则 返回真 not exists 里面只要有数据就返回 false,只要记住 exists 里面有数据就为真就行,这样比较不会混淆

posted @ 2017-03-10 19:00  小琪子  阅读(889)  评论(0)    收藏  举报