SQLite中的批量更新
我有两个具有相同结构的表,我想使用另一个表中的数据更新一个表,匹配主键。SQLite有一个with(CTE)语句,但以下语句不起作用(sqlite3 v.3.29.0):SQLite中的批量更新,sqlite,Sqlite,我有两个具有相同结构的表,我想使用另一个表中的数据更新一个表,匹配主键。SQLite有一个with(CTE)语句,但以下语句不起作用(sqlite3 v.3.29.0): 我尝试过使用“select main.ID as ID,temp.Desc as Desc”,但得到了相同的错误消息。要从cte更新主表,请使用子查询,因为sqlite不支持从更新 with mapping as (select main.ID, temp.Desc from main join temp on te
我尝试过使用“select main.ID as ID,temp.Desc as Desc”,但得到了相同的错误消息。要从
cte
更新主表,请使用子查询,因为sqlite
不支持从更新
with mapping as
(select main.ID, temp.Desc
from main
join temp on temp.ID=main.ID)
update main set Desc=
(select Desc from mapping where ID = main.ID limit 1);
请看我会试试这个,我怀疑它会让我做我需要做的事情。但是,我要指出,我没有使用任何称为“更新自”的东西。根据文档,我可以用一个CTE作为update语句的开头,我所要做的就是在普通update语句中从该CTE中选择一个字段。在我看来仍然像一个SQLite bug。但是,当然,谢谢你的信息。
with mapping as
(select main.ID, temp.Desc
from main
join temp on temp.ID=main.ID)
update main set Desc=
(select Desc from mapping where ID = main.ID limit 1);