I have two tables, first table (table1):
| Field | Type | Null | Key | Default | Extra |
+----------+------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | MUL | NULL | |
| who_id | int(11) | NO | MUL | NULL | |
| ts | int(11) | NO | MUL | NULL | |
+----------+------------+------+-----+---------+----------------+
second table (table2):
+----------+------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+----------+------------+------+-----+---------+----------------+
| id | bigint(20) | NO | PRI | NULL | auto_increment |
| user_id | int(11) | NO | MUL | NULL | |
| owner_id | int(11) | NO | MUL | NULL | |
| ts | int(11) | NO | | NULL | |
| was_read | tinyint(1) | NO | | NULL | |
+----------+------------+------+-----+---------+----------------+
I want to delete data from table1
and table2
in one query by criteria
WHERE table1.ts < UNIX_TIMESTAMP() - 30 * 24 * 60 * 60 AND table1.user_id = table2.user_id AND table1.who_id = table2.owner_id
Need a query similar to this but with LIMIT
:
DELETE t1, t2
FROM table1 t1, table2 t2
WHERE t1.ts < UNIX_TIMESTAMP() - 30 * 24 * 60 * 60
AND t1.user_id = t2.user_id AND t1.who_id = t2.owner_id;
Columns id does not intersect