How to delete multiple rows in sqlite database

2019-09-21 01:40发布

问题:

I have a table in sqlite database which consists of 61249 rows in that i just need 873 rows rest of the rows have to be deleted. I tried it by using loops concept but unfortunately. I am using dbbrowser sqlite to access this database. we cant use loops here can any one solve this.

回答1:

if you know how to select your 873 rows from your table you should do something do like this. Here is how to delete all rows except selected, in this example all rows except those where id is between 3 and 5...

 DELETE FROM table1
 WHERE id NOT IN (SELECT id FROM table1 WHERE id BETWEEN 3 AND 5);

Here is SQL Fiddle for that to see how that look like http://sqlfiddle.com/#!7/3d657/1