I need to delete all dates from database except first two selected dates:
SELECT DateColumn
FROM Table
GROUP BY date(DateColumn)
ORDER BY DateColumn DESC
I want in one query to delete all dates except first two.
delete from table where DateColumn not in(
SELECT DateColumn
FROM Table
GROUP BY date(DateColumn)
ORDER BY DateColumn DESC LIMIT 2)
DELETE FROM Table
WHERE DateColumn NOT IN (SELECT DateColumn
FROM Table
GROUP BY date(DateColumn)
ORDER BY DateColumn DESC
LIMIT 2);