sqlite多表關聯update

來源:互聯網
上載者:User

標籤:blog   div   from   gpo   sqlite資料庫   table   語句   多表   log   

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 table1set  num1 = (select num2 from table2 where table2.pid=table1.id)
where...

更新多個欄位時:

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

 

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

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

 

sqlite多表關聯update

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.