Get the App
SLTechnology News&Howtos  ›  Database  › 

How to use Update to realize multi-table joint update in SQL

Shulou Source: shulou.com Published: 2022-05-31 19:34:12 10月06日 Update

This article will explain in detail how to use Update to achieve multi-table joint update in SQL, the content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.

(1) sqlite multi-table update method

The copy code is as follows:

/ /--

Update t1 set col1=t2.col1

From table1 t1

Inner join table2 t2 on t1.col2=t2.col2

This is a very simple batch update statement that supports this syntax in SqlServer but not in sqlite

Sqlite can be converted to the following syntax

The copy code is as follows:

Update table1 set col1= (select col1 from table2 where col2=table1.col2)

Update ta_jbnt_tzhd_pht_Area_xiang set T1 = (select sys_xzqhdm.name from sys_xzqhdm

Where t2=sys_xzqhdm.code)

(2) SQL Server multi-table update method

The copy code is as follows:

/ /--

SQL Server syntax: UPDATE {table_name WITH (

< table_hint_limited >

[. N]) |

View_name | rowset_function_limited} SET {column_name = {expression | DEFAULT

| | NULL} | @ variable = expression | @ variable = column = expression} [,... n] |

{{[FROM {

< table_source >

} [,... n]] [WHERE

< search_condition >

]} | [

WHERE CURRENT OF {{[GLOBAL] cursor_name} | cursor_variable_name}]} [

OPTION (

< query_hint >

[,. N])]

SQL Server example:

The copy code is as follows:

Update a set a.gqdltkscompilb.gqdltksMagnetica.bztkscompilb.bztks from

Landleveldata a,gdqlpj b where a.GEO_Code=b.lxqdm

Update method of multiple tables in access Database

The copy code is as follows:

X = "update" + DLTB + "an inner join tbarea2 b on a.objectid=b.FID set a." + fd_dltb_xzdwmj + "= b.area_xzdw, a." + fd_dltb_lxdwmj + "= b.area_lxdw"

SQLList.Add (x)

(3) Oracle multi-table update method

Oracle syntax:

The copy code is as follows:

UPDATE updatedtable SET (col_name1 [, col_name2...]) = (SELECT

Col_name1, [, col_name2...] FROM srctable [WHERE where_definition])

Oracel example:

The copy code is as follows:

Update landleveldata a set (a.gqdltks, a.bztks) = (select b.gqdltks

B.bztks from gdqlpj b where a.GEO_Code=b.lxqdm)

(4) MySQL multi-table update method

MySQL syntax:

The copy code is as follows:

UPDATE table_references SET col_name1=expr1 [, col_name2=expr2...]

[WHERE where_definition]

MySQL example:

The copy code is as follows:

Update landleveldata a, gdqlpj b set a.gqdltks = b.gqdltks, a.bztks=

B.bztks where a.GEO_Code=b.lxqdm

On how to use Update in SQL to achieve multi-table joint update is shared here, I hope the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Code updates methods syntax examples unions content articles more knowledge articles a. support yes convertible data database statements quality this is Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno NVidia vpn Huawei MySQL Linux