If the number was more than 10 records, Old records clean. that's mean,If the 15 records stored in the table, 5 first records to be erased.
Example:
"DELETE FROM Table WHERE ID NOT IN (SELECT ??? 10 ID FROM Table)"
If the number was more than 10 records, Old records clean. that's mean,If the 15 records stored in the table, 5 first records to be erased.
Example:
"DELETE FROM Table WHERE ID NOT IN (SELECT ??? 10 ID FROM Table)"
Copyright © 2021 Jogjafile Inc.
In SQL Server, you can use
row_number()
to enumerate the values and then delete the oldest ones usingwhere
:Your approach also works. You can do:
Note: This uses
not in
, so it assumes thatid
is neverNULL
. That seems reasonable in this situation.