SQL updates multiple fields with subquery results

Source: Internet
Author: User

Iamlasong

Requirements: The contents of the table need to be changed, the content of the change is placed in a temporary table, and the SQL statement is used to update multiple fields in the formal table.

If you update a field directly with the field name = subquery, multiple fields are updated, and the fields are written in parentheses, as follows:

Update TB_JG T
Set t.jgfl = ' SD ',
(T.zj_code, T.ZJ_MC) = (select A.zj_code, A.ZJ_MC
From Song_temp A
where A.zj_code = T.zj_code)
where exists (select 1 from song_temp a where a.zj_code = T.zj_code)

Requirements: Create a table from a subquery, with the following statement:

CREATE TABLE SNCN_ZD_JG as SELECT * from TB_JG where zdbz= ' 1 ' ORDER by City_code,xs_code;

If the table already exists, the following statement can insert the query result:
INSERT INTO SNCN_ZD_JG select * from TB_JG where zdbz= ' 1 ' ORDER by City_code,xs_code;


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.