Author: Iamlasong
Requirements: Table content needs to be changed, changes in temporal table content, use of SQL official statement to update the table in several areas.
Suppose that you update a field directly with the field name = subquery, multiple fields are updated, and the fields are written in parentheses, such as the following:
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, such as the following:
CREATE TABLE SNCN_ZD_JG as SELECT * from TB_JG where zdbz= ' 1 ' ORDER by City_code,xs_code;
Suppose the table already exists. The following statement inserts the query result:
INSERT INTO SNCN_ZD_JG select * from TB_JG where zdbz= ' 1 ' ORDER by City_code,xs_code;
Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.
SQL updates multiple fields with sub-query results