zoukankan      html  css  js  c++  java
  • 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)
  • 相关阅读:
    畅通工程续
    find the safest road
    Window Pains
    什么是DO / DTO / BO / VO /AO ?
    编程四大件
    1.Redis简介和安装
    0.Redis课程大纲
    8.docker容器虚拟化与传统虚拟机比较
    7.docker私有仓库
    6.Docker服务编排
  • 原文地址:https://www.cnblogs.com/mafeng/p/8505540.html
Copyright © 2011-2022 走看看