Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete all rows with timestamp older than x days

People also ask

How do I purge old data in mysql?

To delete all rows older than 30 days, you need to use the DELETE with INTERVAL. Use < now() i.e. less than operator to get all the records before the current date.

Which statement type would be used to remove transactions more than one year old from a table?

Answer: C. TRUNCATE is a DDL command. It removes the records from the table without any condition. It is not the part of any ongoing transaction and an uncommitted transaction in the session is committed after TRUNCATE is executed.


DELETE FROM on_search 
WHERE search_date < UNIX_TIMESTAMP(DATE_SUB(NOW(), INTERVAL 180 DAY))

DELETE FROM on_search WHERE search_date < NOW() - INTERVAL N DAY

Replace N with your day count