Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make an UPDATE while joining tables on SQLite?

I tried :

UPDATE closure JOIN item ON ( item_id = id )  SET checked = 0  WHERE ancestor_id = 1 

And:

UPDATE closure, item  SET checked = 0  WHERE ancestor_id = 1 AND item_id = id 

Both works with MySQL, but those give me a syntax error in SQLite.

How can I make this UPDATE / JOIN works with SQLite version 3.5.9 ?

like image 642
e-satis Avatar asked Apr 21 '09 16:04

e-satis


People also ask

Can you UPDATE a joined table SQL?

SQL UPDATE JOIN could be used to update one table using another table and join condition. UPDATE tablename INNER JOIN tablename ON tablename.

How can you UPDATE the existing records from a table in SQLite?

Introduction to SQLite UPDATE statement First, specify the table where you want to update after the UPDATE clause. Second, set new value for each column of the table in the SET clause. Third, specify rows to update using a condition in the WHERE clause. The WHERE clause is optional.


1 Answers

You can't. SQLite doesn't support JOINs in UPDATE statements.

But, you can probably do this with a subquery instead:

UPDATE closure SET checked = 0  WHERE item_id IN (SELECT id FROM item WHERE ancestor_id = 1); 

Or something like that; it's not clear exactly what your schema is.

like image 51
Andrew Watt Avatar answered Sep 21 '22 14:09

Andrew Watt