DELETE query

Results 1 to 2 of 2

Thread: DELETE query

  1. #1
    Join Date
    Dec 1969

    Default DELETE query

    I want to delete all but the 10 most recent records from a table. I was thinking about this and cannot think of a way to do it. This way the table never contains more than 10 records.<BR><BR>The only thing ive come up with is to use the Date field and each time a new record is added delete to oldest record, so that it works like a circular log.<BR><BR>Anyone have any better ideas?

  2. #2
    Join Date
    Dec 1969

    Default RE: DELETE query

    Off the top of my head how about:<BR><BR>DELETE table WHERE id NOT IN(SELECT TOP 10 id FROM table ORDER BY date DESC)<BR><BR>That should delete everything that wasn&#039;t in the 10 most recent dates, shouldn&#039;t it?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts