我有两张桌子, 第一个表(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 | |
+----------+------------+------+-----+---------+----------------+
第二张表(表2):
+----------+------------+------+-----+---------+----------------+
| 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 | |
+----------+------------+------+-----+---------+----------------+
我想按条件table1
table2
和WHERE table1.ts < UNIX_TIMESTAMP() - 30 * 24 * 60 * 60 AND table1.user_id = table2.user_id AND table1.who_id = table2.owner_id
中的数据
需要与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;
列ID不相交