我有 2 张桌子。table1 有 200 万条记录,table2 有 1100 万条记录我想从 table2 中删除 table1 我如何在 MySQL 中执行此操作,对于这个数据计数需要多少?谢谢你。
问问题
260 次
4 回答
2
听起来您想删除表 2 中与表 1 中的记录匹配的所有记录。如果是这样,您可以使用子查询。我不确定这对您拥有的记录数量有多有效,但以下应该有效:
DELETE FROM table2 where table2.phonenumber IN (select phonenumber from table1);
于 2012-10-03T19:28:45.367 回答
1
SELECT Table2.* FROM Table2 JOIN Table1 ON Table2.phone = Table1.phone WHERE Table2.phone is not null
DELETE Table2.* FROM Table2 JOIN Table1 ON Table2.phone = Table1.phone WHERE Table2.phone is not null
于 2012-10-03T19:29:43.783 回答
1
Delete from table2
where number in (Select number from table1)
于 2012-10-03T19:30:10.640 回答
0
尝试加入,然后从加入中删除
SELECT tbl1.MyId FROM table1 tbl1
JOIN table2 on tbl1.phonenumber = tb2.phonenumber
然后从中删除
如
DELETE FROM Table2 WHERE MyID IN
(SELECT tbl1.MyId FROM table1 tbl1
JOIN table2 on tbl1.phonenumber = tb2.phonenumber)
这是sql代码,不确定mysql有什么变化
祝你好运!
于 2012-10-03T19:27:12.713 回答