¿Cómo hago una ACTUALIZACIÓN al unirme a tablas en SQLite?


Lo intenté:

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

Y:

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

Ambos funcionan con MySQL, pero eso me da un error de sintaxis en SQLite.

¿Cómo puedo hacer que esta ACTUALIZACIÓN / UNIÓN funcione con SQLite versión 3.5.9 ?

Author: shA.t, 2009-04-21

2 answers

No se puede. SQLite no admite uniones en instrucciones de ACTUALIZACIÓN.

Pero, probablemente puede hacer esto con una subconsulta en su lugar:

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

O algo así; no está claro exactamente cuál es tu esquema.

 122
Author: Andrew Watt,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2009-04-21 19:51:23

También puede usar REEMPLAZAR luego puede usar selección con uniones. Así:

REPLACE INTO clusure 
 SELECT sel.col1,sel.col2,....,sel.checked --checked should correspond to column that you want to change
FROM (
 SELECT *,0 as checked FROM closure LEFT JOIN item ON (item_id = id) 
 WHERE ancestor_id = 1) sel
 6
Author: Lemberg,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-12-12 11:07:33