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)

双表进行更新操作

update OutDates set KeshiId = (select KeshiId from  KehuKeshi where   KehuKeshi.KehuId=OutDates.KehuId ) 

转载:https://blog.csdn.net/weixin_33905756/article/details/85973977

最简明的多表操作uypdate

--方式1
UPDATE a SET WtNo=b.NO
from WT_Task a
JOIN WT_BasicInformation b ON a.WtId=b.ID

--方式2
UPDATE a SET a.WtNo=b.NO
FROM WT_Task a,WT_BasicInformation b
WHERE a.WtId=b.ID  
  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值