Home > Database > Mysql Tutorial > sql update如何多表关联更新?(代码示例)

sql update如何多表关联更新?(代码示例)

PHPz
Release: 2019-05-15 14:52:45
Original
9475 people have browsed it

本文总结了在SQL Server,Oracle,MySQL中Update语句多表关联更新的方法。有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助。

sql update如何多表关联更新?(代码示例)

在本例中:我们要用表gdqlpj中的gqdltks,bztks字段数据去更新landleveldata中的同字段名的数据,条件是当landleveldata 中的GEO_Code字段值与gdqlpj中的lxqdm字段值相等时进行更新。

SQL Server语法:

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 ] ) ]
Copy after login

SQL Server示例:

update a set a.gqdltks=b.gqdltks,a.bztks=b.bztks from
landleveldata a,gdqlpj b where a.GEO_Code=b.lxqdm
Copy after login

Oracle语法:

UPDATE updatedtable SET (col_name1[,col_name2...])= (SELECT
col_name1,[,col_name2...] FROM srctable [WHERE where_definition])
Copy after login

Oracel 示例:

update landleveldata a set (a.gqdltks, a.bztks)= ( b.gqdltks,
b.bztks from gdqlpj b where a.GEO_Code=b.lxqdm)
Copy after login

MySQL语法:

UPDATE table_references SET col_name1=expr1 [, col_name2=expr2 ...]
[WHERE where_definition]
Copy after login

MySQL 示例:

update landleveldata a, gdqlpj b set a.gqdltks= b.gqdltks, a.bztks=
b.bztks where a.GEO_Code=b.lxqdm
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template