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);
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