Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deleting records before a certain date

How would I go about deleting all records from a MySQL table from before a certain date, where the date column is in DATETIME format?

An example datetime is 2011-09-21 08:21:22.

like image 235
Hard worker Avatar asked Dec 02 '11 16:12

Hard worker


People also ask

How do I delete a specific record?

We can delete a single record or multiple records depending on the condition we specify in the WHERE clause. Basic Syntax: DELETE FROM table_name WHERE some_condition; table_name: name of the table some_condition: condition to choose particular record.

How do I delete a specific record in a table?

In this article, we learned about the different ways to delete information from a SQL table. This is the basic syntax for using the DELETE query: DELETE FROM table_name WHERE condition of which row(s) to delete; If you want to delete one row from the table, then you have to specify a condition.

How do I delete old records in SQL Server?

So the delete statement is used to delete rows from a table using the where clause to select only the rows to be deleted. Always use a unique identifier to locate the rows that you need to delete. To delete all the rows in a table, always use TRUNCATE TABLE.


1 Answers

DELETE FROM table WHERE date < '2011-09-21 08:21:22'; 
like image 105
Michael Mior Avatar answered Oct 11 '22 14:10

Michael Mior