Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite: delete all records from table specified in another table

Having tables like this

mytab       deltab
---------   --------
id | name   id | name
 1 | Ann     2 | Bob
 2 | Bob     3 | Cindy
 3 | Cindy
 4 | Dave

I'd like to perform query which deletes all records in mytab specified in deltab, so only Ann and Dave would be left in mytab.

While there is MySQL multiple-table delete syntax, looks like there is no such thing in SQLite delete syntax.

I am considering REPLACE syntax with select-stmt and mark the rows which will be deleted (like set these names to NULL) in DELETE query after. I wonder if there is more effective way?

like image 646
Jan Turoň Avatar asked Jul 09 '26 07:07

Jan Turoň


1 Answers

Try this query

Delete from mytab where id in (select id from deltab);
like image 100
Lokesh Kumar Avatar answered Jul 14 '26 16:07

Lokesh Kumar