Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SQLite中的批量更新_Sqlite - Fatal编程技术网

SQLite中的批量更新

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

我有两个具有相同结构的表,我想使用另一个表中的数据更新一个表,匹配主键。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 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);