我试过了 :
UPDATE closure JOIN item ON ( item_id = id ) SET checked = 0 WHERE ancestor_id = 1
和:
UPDATE closure, item SET checked = 0 WHERE ancestor_id = 1 AND item_id = id
两者都适用于MySQL,但那些在SQLite中给我一个语法错误.
如何使这个UPDATE/JOIN与SQLite版本3.5.9一起使用?
你不能.SQLite 不支持UPDATE语句中的JOIN.
但是,您可以使用子查询来执行此操作:
UPDATE closure SET checked = 0 WHERE item_id IN (SELECT id FROM item WHERE ancestor_id = 1);
或类似的东西; 目前还不清楚你的架构究竟是什么.
您也可以使用REPLACE,然后您可以使用连接选择.像这样:
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