sqlite多表關聯update


sqlite數據庫的update多表關聯更新語句,和其他數據庫有點小不一樣

 

比如:在sql server中:

用table1的 id 和 table2的 pid,關聯table1 和 table2 ,將table2的num字段的值賦給table1的num字段

update table1 
set num1 = t2.num2
FROM table1 t1 INNER JOIN table2 t2
ON t1.id=t2.pid;

很容易就關聯起來了

 

sqlite卻不支持這種關聯,可以這樣:

(1)set時,要將table2的num2的值賦給table1的num1字段,要select一下table2,並在括號關聯起來

update table1
set  num1 = (select num2 from table2 where table2.pid=table1.id)
where...

更新多個字段時:

update table1
set  num1 = (select num2 from table2 where table2.pid=table1.id),
num11 = (select num22 from table2 where table2.pid=table1.id)
where...

 

(2)where時,也一樣,比如我就將上面的改一下

update table1
set  num = 99
where table1.id=(select pid from table2 where table2.pid=table1.id)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM