我现在有两张表
表A 一个字段 aa
表B 两个字段 bb cc
我要删除表A中所有 aa=bb 的数据
其中表A,B中都有几w条数据,我用一下的语句,执行起来特别的慢.delete from A where exists ( select aa from A ,B where aa=bb )
表A 一个字段 aa
表B 两个字段 bb cc
我要删除表A中所有 aa=bb 的数据
其中表A,B中都有几w条数据,我用一下的语句,执行起来特别的慢.delete from A where exists ( select aa from A ,B where aa=bb )
用in好像好一点儿。
这样对?
子查询结果不为空,删除表A所有数据
From A Inner Join B On A.aa=B.bb
这样对?
子查询结果不为空,删除表A所有数据B 和 A 不存在主外键关系,是人为让他们关联的
上面的语句是没有错的,可是执行起来特别的慢,因为两个表都有十几万条数据,而实际删除的数据只有几十条, 我改用in试了一下,速度快多了.谢谢各位.
From A Inner Join B On A.aa=B.bb删除19条数据 0:00:17delete from A where exists ( select aa from A ,B where aa=bb )删除19条数据 0:02:47
delete from A where exists(select * from B where A.aa=B.bb)
我试过了,也比较慢的和
delete from A where exists ( select aa from A ,B where aa=bb )
差不多
From A Inner Join B On A.aa=B.bb数据量大的话应该上边的这个最快
delete from A from A inner join B on A.aa=B.bb2.第二种可能的语句://这种肯定是最慢的
delete from A where exists ( select 1 from A ,B where aa=bb )3.第三种可能的语句:
delete from A where exists ( select 1 from B where aa=bb )------------------------------------------------
具体的速度,会与bb或者aa上是否有索引相关联。