mysql - 从一个查询中的两个表中删除

时间:2012-03-24 17:05:13

标签: mysql sql

谁可以帮我做以下查询工作......

两个表都有字段month,year和userId。我希望删除两个表中的行,以获得月和年的完全相同的值。

从表1,表2中删除 Table1.month NOT IN(1,2) AND Table1.year NOT IN(1,2) AND Table1.userId = 1 AND Table2.userId = Table1.userId

感谢。

1 个答案:

答案 0 :(得分:4)

DELETE FROM Table1, Table2
USING Table1, Table2
WHERE Table1.month NOT IN (1,2)
  AND Table1.year NOT IN (1, 2)
  AND Table1.userId = 1
  AND Table2.userId = Table1.userId

http://dev.mysql.com/doc/refman/5.5/en/delete.html