Go SQLite Data Multi-table federated update

Source: Internet
Author: User
Tags sqlite

In fact, in MySQL, multi-table joint update is not difficult.

Grammar:

UPDATE SET col_name1=[, COL_NAME2=EXPR2 ... ][WHERE where_definition]

Example:

UPDATE SET table1.value=Table2.value, a.type=WHERE table1.sid=

Similarly, in SQL Server, it is possible to use federation as a simple implementation:

UPDATE SET col1=fromINNERJOIN on t1.col2=

However, unfortunately, in SQLite does not support such a syntax, it is not in SQLite does not support multi-table joint update it? Of course not, in fact, SQLite in the multi-table joint update can also be achieved,

First of all, SQLite has a fresh thing "INSERT OR REPLACE", similar to MySQL, this structure can be guaranteed to be replaced in the presence of the situation, the non-existent situation of the update, with this mechanism can easily implement the update ... From the.

INSERT OR REPLACE  into T1 (keySELECT T2.  KeyfromWHERE T2. Key = T1. Key

This approach avoids insertions, first ensuring that updates are performed according to the primary key, which can be a bit cumbersome if the where condition is not the primary key.

Do you want to update the primary key? Is there another way to do it? We can only ask the typical update...where for help in this case, here is an example:

UPDATE SET = 1 WHERE = (SELECTfromWHERE=and=5

Go SQLite Data Multi-table federated 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.