【SQL】sql update 多表关联更新方法总结
#表结构:
1、表一:Test1
| Id | name | age |
| 1 | ||
| 2 |
2、表二:Test2
| Id | name | age |
| 1 | 小明 | 10 |
| 2 | 小红 | 8 |
#实现将表Test2的name和age字段数据更新到表Test1中,按照id相等的条件
1、SQLServer多表更新方法:
语法:
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 ] ) ]
例子:
update test1
set test1.name=test2.name,test1.age=test2.age
from test1
inner join test2
on test1.id=test2.id
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)
3、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
4、通用方法:(*^__^*)
update test1
set name=(select name from test2 where test2.id=test1.id),
age=(select age from test2 where test2.id=test1.id)
———————————————————————————————————————————————————
【SQL】sql update 多表关联更新方法总结的更多相关文章
- Oracle\MS SQL Server Update多表关联更新
原文:Oracle\MS SQL Server Update多表关联更新 一条Update更新语句是不能更新多张表的,除非使用触发器隐含更新.而表的更新操作中,在很多情况下需要在表达式中引用要更新的表 ...
- MSSQL update 多表关联更新
update tMeter set 字段= t.源自段 from ( select * from 源表信息 ) t where 关联条件 实际demo: UPDATE dbo.WX_TWODIMENC ...
- mysql update 多表关联更新
UPDATE new_schedules_spider_static_schedule s join new_scac_port p on p.`PORT` = s.`PORT` and p.SCAC ...
- 书写 sql 中关于 update 多表联合更新的方法
SQL Update多表联合更新的方法(1) sqlite 多表更新方法//----------------------------------update t1 set col1=t2.col1fr ...
- 170823、SQL Update多表联合更新的方法
SQL Update多表联合更新的方法 (1) sqlite 多表更新方法 update t1 set col1=t2.col1 from table1 t1 inner join table2 t2 ...
- SQL Update多表联合更新的方法
SQL Update多表联合更新的方法 (1) sqlite 多表更新方法 update t1 set col1=t2.col1 from table1 t1 inner join table2 t2 ...
- MySQL 多表关联更新及删除
目录: <MySQL中的两种临时表> <MySQL 多表关联更新及删除> <mysql查询优化之三:查询优化器提示(hint)> 一. 多表关联更新 问题 ...
- 数据库MySQL中关于“多表关联更新”的那些事
在常见的sql中,我们经常在查询中进行多表关联查询,用的比较熟练.今天在开发中遇到一个实际业务场景是多表关联更新,一时不知所措.本着多学习的态度,没有直接写java代码去实现,终于把多表关联更新的sq ...
- Oracle SQL性能优化 - 根据大表关联更新小表
需求: 小表数据量20w条左右,大表数据量在4kw条左右,需要根据大表筛选出150w条左右的数据并关联更新小表中5k左右的数据. 性能问题: 对筛选条件中涉及的字段加index后,如下常规的updat ...
随机推荐
- Gulp Error: Cannot find module 'jshint/src/cli'
I'm following sitepoint's An introduction to Gulp.js, but I'm stuck on step four, when I try to run ...
- CentOS 7 安装 .Net Core 2.0 详细步骤
轰轰烈烈的Core 热潮,从部署环境开始.参照了网上不少前辈的教程,也遇到不少的坑,这边做个完整的笔记. 一.构建.Net core 2的应用程web发布,因为是用来测试centos上的core 环境 ...
- C# if---else---练习题整理
if else 语句是到今天为止学习的第一个完整的语句,把有意思的练习题整理下来开一下脑洞!!! 练习一简单的人工智能 1 static void Main(string[] args) ...
- Ubuntu安装SSH SERVER
apt-get update apt-get install openssh-server 安装好后查看SSH是否启动 打开”终端窗口”,输入”sudo ps -e |grep ssh“–>回车 ...
- 【原】Dubbo 多版本号过渡
之前发过一篇因为接口规范的问题导致其它端出现服务不可用的文章(http://www.cnblogs.com/zdd-java/p/8612763.html),然而最近在查阅了dubbo官方指南文档才知 ...
- Placement of class definition and prototype
When I create a function, I can put the code for it after main if I put the prototype above main. Fo ...
- sql server: left join 重复数据
---涂聚文 2017-9-28 SELECT VipExamMailProjectId,VipExamMailStaffID FROM VipExamMailRecord WHERE VipExam ...
- linux定时任务调度定系统——opencron
linux定时任务调度定系统——opencron https://gitee.com/terrytan/opencron/#%E8%BF%90%E8%A1%8C%E7%8E%AF%E5%A2%83 一 ...
- redis 在Linux下的安装与配置
redis在Linux下的安装与配置 by:授客 QQ:1033553122 测试环境 redis-3.0.7.tar.gz 下载地址: http://redis.io/download http: ...
- git本地仓库关联多个remote,怎么用本地一个分支向不同remote不同分支推送代码
我想这个问题,是大家关注的问题,这个问题,我非常关注. 背景:在公司开发项目,我们一般都要把项目推送到公司领导创建的一个远程仓库里边去,但是我们同时也有自己的小仓库,这样的话,如何方便的将我们的代码, ...