MySQL Forums
Forum List  »  Oracle

Delete all rows in table but keep the last recent 2
Posted by: yvonne kire
Date: September 23, 2009 01:34PM

I want to keep the last two most recent records in a table and delete anything else - any ideas how this would be acomplished?

I have a ID column and CREATE_DATE column
I can either sort by CREATE_DATE - and keep the last two

All other data that needs to be purged out.
How can accomplish this?

max(ID) or max(CREATE_DATE) find the newest record
how do I find the following record?
select (max(ID) -1 ) doesnot work since the ID are not sequential

| 26821 |
| 27963 |
| 28007 |
| 28131 |
| 28197 |
+-------------------------+

Options: ReplyQuote


Subject
Views
Written By
Posted
Delete all rows in table but keep the last recent 2
14927
September 23, 2009 01:34PM


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.