根据来自不同表的数据从表中删除记录

时间:2010-05-21 18:53:04

标签: sql mysql

table1包含列CITY和COUNTRY。 table2有列CITY。

如何从table2中删除所有与table1共有CITY的记录,以及COUNTRY ='Russia'?

请记住,两个表都有大约100万行数据

2 个答案:

答案 0 :(得分:1)

您可以使用multitable delete syntax

DELETE table2
FROM table1
JOIN table2
ON table1.city = table2.city
WHERE table1.country = 'RUSSIA'

答案 1 :(得分:1)

DELETE table2
FROM table2 INNER JOIN table1
   ON table2.CITY = table1.CITY
WHERE table1.COUNTRY = 'Russia'