BCS*_*BCS 52 mysql join not-exists
我有2个表(A和B)具有相同的主键.我想选择A中的所有行而不是B中的行.以下工作:
select * from A where not exists (select * from B where A.pk=B.pk);
Run Code Online (Sandbox Code Playgroud)
但是看起来很糟糕(A中只有10万行~2秒,B中只有3-10k行)
有没有更好的方法来运行它?也许作为左联盟?
select * from A left join B on A.x=B.y where B.y is null;
Run Code Online (Sandbox Code Playgroud)
在我的数据上,这似乎运行得稍快(~10%),但总的来说呢?
Nic*_*rdi 55
我认为你最后的陈述是最好的方式.你也可以试试
SELECT A.*
from A left join B on
A.x = B.y
where B.y is null
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
62606 次 |
最近记录: |