Reputation: 41
hi guys im frustating about this query,
lets make this clear first
i have the table :
table1 table2 table3 table4
and each tables have some foreign key relation with other let says
table1 --> table2 --> table3 --> table 4
but only table3 have date-time column
how can i delete record from those table if older than 10 seconds
i try
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)
but its error
Unknown column 'timestamp' in 'where clause'
Upvotes: 0
Views: 584
Reputation: 462
DELETE FROM table1 JOIN table3 ON table1.constraint_field=table3.constraint_field WHERE timestamp > (NOW() - INTERVAL 1 SECOND)
And remember to set CASCADE on DELETE for the constraints.
Upvotes: 1