SQLite Multi-table associated update

Source: Internet
Author: User
Tags sqlite sqlite database

Updated multi-table associated UPDATE statement for SQLite database, which is a little bit different from other databases

For example: In SQL Server:

Assign the value of the Table2 num field to the Table1 num field with the Table1 ID and the table2 PID, associated table1, and table2


Set num1 = t2.num2

On T1.id=t2.pid;

It's easy to link up.

SQLite does not support this association, so you can:

(1) Set, to assign the value of the Table2 num2 to the Num1 field of table1, select Table2 and associate with parentheses

Update Table1set  num1 = (select num2 from table2 where table2.pid=table1.id)
where ...

When updating multiple fields:

Update Table1set  num1 = (select num2 from table2 where table2.pid=table1.id), Num11 = (select Num22 from table2 where T Able2.pid=table1.id) where ...

(2) where is the same, for example, I will change the above

Update table1set  num = 99where table1.id= (select PID from table2 where Table2.pid=table1.id)

SQLite Multi-table associated update

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.