我想从一个表中选择数据,如下所示 ID|FOO|城市|酒吧
还有另一个表,其中将存储已选择的所有数据,以便我获得唯一的结果。这张表看起来像 ID|ID_from_other_table
现在我陷入困境,是否应该使用左连接或联合? 哪一个更快,我该如何正确设置?
最佳答案
left join
在 MySQL 中可能会比其他反连接模式(如 not in
)更快。和not exists
.
select t1.*
from table1 t1
left join table2 t2 on t1.id = t2.id_from_other_table
where t2.id is null
关于MySql 通过排除另一个表中的所有 id 进行选择,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31209622/