Delete all, left only the last 10 records.

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have a table which stores events made by users. Each record has timestamp
which is the time it was created. I want upon openning database, remove all
old records and left only the last 10 records. Can I do that by one SQL
command ?

I want to execute
DoCmd.runSQL sqlstatement

But I can not figure out that SQLstatement.

Thanks for help
Quang
 
Tran said:
Hi,
I have a table which stores events made by users. Each record has
timestamp which is the time it was created. I want upon openning
database, remove all old records and left only the last 10 records.
Can I do that by one SQL command ?

I want to execute
DoCmd.runSQL sqlstatement

But I can not figure out that SQLstatement.

Thanks for help
Quang

DELETE * FROM TableName
WHERE PrimaryKeyField Not In(SELECT TOP 10 PrimaryKeyField FROM TableName ORDER
BY TimeStampField DESC)
 
Back
Top