3

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.

4

2 回答 2

4
delete from table where DateColumn not in(
SELECT DateColumn 
FROM Table 
GROUP BY date(DateColumn) 
ORDER BY DateColumn DESC LIMIT 2)
于 2012-10-31T09:20:08.207 回答
3
DELETE FROM Table
      WHERE DateColumn NOT IN (SELECT DateColumn 
                                 FROM Table 
                             GROUP BY date(DateColumn) 
                             ORDER BY DateColumn DESC
                                LIMIT 2);
于 2012-10-31T09:20:14.717 回答