[SQL] UPDATE多表更新
表结构:
| id | name | age |
| 1 | ||
| 2 |
2、表二:Test2
| id | name | age |
| 1 | 小明 | 10 |
| 2 | 小红 | 8 |
3.1、Mysql多表更新:
语法:
UPDATE table_references
SET col_name1=expr1 [, col_name2=expr2 ...] [WHERE where_definition]
例子:
update test1,test2
set test1.name=test2.name,test1.age=test2.age
where test1.id=test2.id
3.2 、Oracle多表更新:
语法:
UPDATE updatedtable
SET (col_name1[,col_name2...])= (SELECT col_name1,[,col_name2...]
FROM srctable [WHERE where_definition])
例子:
update test1
set (test1.name,test1.age)=
(select test2.name,test2.age from test2 where test2.id=test1.id)

浙公网安备 33010602011771号