Mysql删除记录超过10秒

时间:2016-08-06 20:44:23

标签: mysql

嗨,大家对此查询感到沮丧,

让我们先说清楚

我有桌子:

表1 表2 表3 表4

并且每个表与其他表有一些外键关系

table1 - > table2 - > table3 - >表4

但只有table3有日期时间列

如果超过10秒

,如何从这些表中删除记录

我试试

DELETE FROM table1 WHERE timestamp < (NOW() - INTERVAL 1 SECOND)

DELETE FROM table2 WHERE timestamp < (NOW() - INTERVAL 1 SECOND)
DELETE FROM table3 WHERE timestamp < (NOW() - INTERVAL 1 SECOND)
DELETE FROM table4 WHERE timestamp < (NOW() - INTERVAL 1 SECOND)

但错误

Unknown column 'timestamp' in 'where clause'

1 个答案:

答案 0 :(得分:0)

DELETE FROM table1 JOIN table3 ON table1.constraint_field=table3.constraint_field WHERE timestamp > (NOW() - INTERVAL 1 SECOND)

请记住在DELETE上为约束设置CASCADE。