How to delete data with a specific row number (sqlite)

I have a people table (name, address, phone), my table has 2000+ rows. I want to delete 1000 lines. How about the request?

+5
source share
2 answers

I assume that you want to remove the "first 1000 lines", given the unsorted order of the result of the "select" query without sorting arguments and no criteria, in which case you are doing something wrong.

But, as an academic exercise, here's how you do it. All rows in SQLite have a field rowidthat you can use to find where these 1000 rows end.

sqlite> create table t(s string);
sqlite> insert into t values('a1');
sqlite> insert into t values('a2');
sqlite> insert into t values('a3');
sqlite> insert into t values('a4');
sqlite> select * from t;
a1
a2
a3
a4
sqlite> delete from t where rowid < (select rowid from t limit 2,1);
sqlite> select * from t;
a3
a4
+9
source

http://www.sqlite.org/lang_delete.html

SQLite

Delete from your_table 
where any_filter_you_wanted_as_well 
order by if_you_have_a_preference
limit 1000
+5

All Articles