PDA

View Full Version : Delete All But The Latest One


Cologne
04-08-2009, 02:22 AM
Hi there,

I got a lots of Database entries. Now I want to delete all but the latest one. How does that work?

Denis

Ian
04-08-2009, 04:45 AM
Just a stab in the dark, but retrieve the recordset ordered by the unique ID field descending.

Store that Unique ID in a Session Variable and then delete all records that are not equal to that Session Variable.

The DA Delete code may need some manual tweaking for that though..

Cheers
Ian

Ray Borduin
04-08-2009, 07:45 AM
You could probably just use a query like:

DELETE FROM tablename WHERE tableID <> (SELECT tableID FROM tablename ORDER BY tableID DESC Limit 1)