SQL join ON 在 Mysql 中不相等

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5040663/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 18:49:47  来源:igfitidea点击:

SQL join ON not equal in Mysql

mysql

提问by Nilesh

I have two tables. Both contains question id field. I want to get all records from first table that are not present in second one. I don't want to use "NOT IN" constrain as second table having more than 400000 records.

我有两张桌子。两者都包含问题 ID 字段。我想从第一个表中获取第二个表中不存在的所有记录。我不想使用“NOT IN”约束作为具有超过 400000 条记录的第二个表。

回答by Adriaan Stander

Try something like

尝试类似的东西

SELECt  t1.*
FROM    Table1 t1 LEFT JOIN
        Table2 t2   ON  t1.questionID = t2.questionID
WHERE   t2.questionID IS NULL

回答by Lieven Keersmaekers

Typically you would do this using a LEFT JOINcombined with a WHEREclause selecting every row where the joined table returns no results.

通常,您可以使用LEFT JOIN结合WHERE子句选择连接表不返回任何结果的每一行来执行此操作。

SELECT t1.*
FROM   Table1 t1
       LEFT OUTER JOIN Table2 t2 ON t2.ID = t1.ID
WHERE  t2.ID IS NULL

回答by Sergey Vedernikov

try:

尝试:

select from t1
right join t2 on t2.id = t1.id where t2.id is null