Click to See Complete Forum and Search --> : help with query


jasongr
01-27-2007, 03:37 PM
Hi people

I have a table that holds information on activities.
For each activity I store the following:
ID, When, Description
The ID is the key for the table
The When column holds the datetime when the activity was added

The table gets filled up pretty quickly.
I would like to run a query that will delete ALL the entries except for the 2500 latest ones. The When column should be the one to use when deciding which are the 2500 latest activities

Can someone show me the most efficient way of doing this?

thanks

NightShift58
01-27-2007, 04:12 PM
Which DBMS?

jasongr
01-27-2007, 04:13 PM
MySQL MyISAM

NightShift58
01-27-2007, 04:23 PM
Try this:SELECT * FROM `activities_table`
ORDER BY `When` DESC
LIMIT 2500, 99999999999999Make sure it works as a SELECT and then substitute with "DELETE FROM"...