Some notes:
- compare the bare column
end_date
against a value, as a date type
- test expressions in SELECT statements, before running DELETE
What is the first date value that is greater than the end_date on the rows you want to delete? Test that expression in a SELECT statement.
SELECT DATE_FORMAT( NOW(), '%Y-01-01') + INTERVAL -3 YEAR
returns
2016-01-01
or, date value four years before now
SELECT DATE(NOW()) + INTERVAL -4 YEAR
returns:
2015-04-05
adjust that expression until it returns the value we need. Then we can include that expression in a statement, comparing to bare column end_date
column, like this:
SELECT m.*
FROM membership m
WHERE m.end_date < DATE(NOW()) + INTERVAL -4 YEAR
ORDER BY m.end_date DESC
or if we know that the date value we need is '2015-04-05'
or '2017-01-01'
then we can just specify that as a literal:
SELECT m.*
FROM membership m
WHERE m.end_date < '2017-01-01' + INTERVAL 0 MONTH
ORDER BY m.end_date DESC
After we confirm that the SELECT statement is returning the set of rows we want to delete, then we can replace the SELECT
keyword with DELETE
.