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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top