开发者

Sql Compact 3.5: Limit number of rows in column

开发者 https://www.devze.com 2023-02-11 16:06 出处:网络
I have a table with rows of the following form: Timestamp D开发者_如何学编程ata: I would like to keep only newest N rows in table, and delete everything rest.

I have a table with rows of the following form: Timestamp D开发者_如何学编程ata: I would like to keep only newest N rows in table, and delete everything rest.

Is there a way to specify deletion of all except N newest rows?


delete from table 
where id not in (
    select top 30 id from table
    order by timestampcolumn desc
)

Here N = 30. You can replace the number 30 by any number you want to retain.

0

精彩评论

暂无评论...
验证码 换一张
取 消