NOT EXISTS vs. NOT IN vs. LEFT JOIN WHERE IS NULL 之间有什么区别? [英] What's the difference between NOT EXISTS vs. NOT IN vs. LEFT JOIN WHERE IS NULL?

查看:19
本文介绍了NOT EXISTS vs. NOT IN vs. LEFT JOIN WHERE IS NULL 之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我看来,您可以在 SQL 查询中使用 NOT EXISTS、NOT IN 或 LEFT JOIN WHERE IS NULL 来执行相同的操作.例如:

It seems to me that you can do the same thing in a SQL query using either NOT EXISTS, NOT IN, or LEFT JOIN WHERE IS NULL. For example:

SELECT a FROM table1 WHERE a NOT IN (SELECT a FROM table2)

SELECT a FROM table1 WHERE NOT EXISTS (SELECT * FROM table2 WHERE table1.a = table2.a)

SELECT a FROM table1 LEFT JOIN table2 ON table1.a = table2.a WHERE table1.a IS NULL

我不确定我的所有语法是否正确,但这些是我见过的一般技术.为什么我会选择使用其中一种?性能不同吗...?其中哪一个是最快/最有效的?(如果取决于实现,我什么时候使用每个?)

I'm not sure if I got all the syntax correct, but these are the general techniques I've seen. Why would I choose to use one over the other? Does performance differ...? Which one of these is the fastest / most efficient? (If it depends on implementation, when would I use each one?)

推荐答案

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆