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
.
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.
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.
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.
DELETE FROM table WHERE date < '2011-09-21 08:21:22';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With