Hosting tutors discussion forum

Full Version: mysql table - delete records older than n days
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I have a mysql database which contains a table having lots of old un used data. The software keeps on filling the table on every trigger.

How I can delete all records older than n days? I already have backups.
You can use mysql delete statement with where and INTERVAL option to delete needed data that is older than x days. For example you can specify to delete all records older than 60 days.
Please provide an example sql statement to delete all records from a table older than n days. There are many examples available, but none of them worked for me.
Here is a delete example. Deletes all records from emails table where a specific subject is used provided the date field is having a value older than 60 days.
Code:
delete FROM tbl_emails WHERE subject='Invoice Payment Confirmation' and date < NOW() - INTERVAL 60 DAY ORDER BY date DESC;