Sqlite remove row count

I need to write a SQLlite query that will remove rows from a table above 200. I thought this would work:

DELETE FROM [tbl_names] WHERE count(*) > 200 

but it gives me: misuse of the cumulative count () function

I know there is a limitation that I can use, but if I use:

 DELETE FROM [tbl_names] LIMIT 200 

it looks like it will delete the first 200 lines.

0
source share
1 answer

All rows in SQLite have a rowid field that you can use to search for rows greater than 200. For example:

 DELETE FROM [tbl_names] WHERE rowid > 200 

You can also use an offset with your limit:

 DELETE FROM [tbl_names] LIMIT 10000 offset 200 

using roqid seems like the best choice.

+2
source

Source: https://habr.com/ru/post/1441524/


All Articles