Re: Delete all rows in table but keep the last recent 2
Posted by:
Garey Guan
Date: September 29, 2009 01:26AM
mysql> select * from t;
+------+-------------+
| idx | create_date |
+------+-------------+
| 1 | 2009-09-19 |
| 3 | 2009-09-20 |
| 4 | 2009-09-22 |
| 6 | 2009-09-24 |
| 8 | 2009-09-26 |
+------+-------------+
5 rows in set (0.00 sec)
mysql> delete from t order by create_date desc limit 2;
Query OK, 2 rows affected (0.01 sec)
mysql> select * from t;
+------+-------------+
| idx | create_date |
+------+-------------+
| 1 | 2009-09-19 |
| 3 | 2009-09-20 |
| 4 | 2009-09-22 |
+------+-------------+
3 rows in set (0.00 sec)
mysql>
Subject
Views
Written By
Posted
15120
September 23, 2009 01:34PM
5678
September 24, 2009 07:28AM
6142
September 24, 2009 04:42PM
5699
September 29, 2009 05:54PM
Re: Delete all rows in table but keep the last recent 2
6146
September 29, 2009 01:26AM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.