flukyspore
flukyspore

Reputation: 696

mysql - deleting from two tables in one query

Who can help me make the following query work...

Both tables have the fields month, year and userId. And I want to delete rows in both Tables for the exact same values for month and year.

DELETE FROM 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

Thanks.

Upvotes: 0

Views: 371

Answers (1)

Amber
Amber

Reputation: 526573

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

Upvotes: 4

Related Questions