Keep only N last records in SQLite database, sorted by date

后端 未结 4 1280
渐次进展
渐次进展 2020-12-13 15:27

I have an SQLite database that I need to do the following: Keep only last N records, sorted by date. How do you do that?

4条回答
  •  粉色の甜心
    2020-12-13 15:57

    To delete all but the latest 10 records.

    delete
    from test
    where id not in (
        select id
        from test
        order by date desc
        limit 10
    )
    

提交回复
热议问题