当前位置:网站首页>【SQL】按某个关联列用一张表的数据更新另一张表
【SQL】按某个关联列用一张表的数据更新另一张表
2022-07-30 03:01:00 【又被平均了】
事件
写MySQL语句时,想要实现“使用某一张表中的字段值,更新另一张表中的字段值”的功能
两张表结构如下:
t1表:
t2表:
查询资料后,写出如下语句:
update t1
set aaa=t2.aaa
from t2
where bbb=t2.bbb;
执行后报错:
1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from t2 where bbb=t2.bbb' at line 3
在查询资料后发现,上述写法是SQL Server的写法,所以在MySQL中会报错
在MySQL中类似的写法为:
update t1,t2
set t1.aaa=t2.aaa
where t1.bbb=t2.bbb;
总结
MySQL中,使用某一张表中的字段值,更新另一张表中的字段值的写法之一:
update tabel_dest,table_src
set tabel_dest.attr = table_src.attr
where condition;
SQL Server中,使用某一张表中的字段值,更新另一张表中的字段值的写法之一:
update tabel_dest
set attr = table_src.attr
from table_src
where condition;
边栏推荐
- Mysql中事务是什么?有什么用?
- leetcode 5 questions a day-Day01
- 动态绑定href url
- Detailed explanation of carousel picture 2 - carousel pictures through left positioning
- ESP8266 +0.96“ I2C OLED 表盘时钟
- CF1473C No More Inversions
- WPF 学习笔记《WPF布局基础》
- HCIP experiment (05) OSPF comprehensive experiment
- 答对这3个面试问题,薪资直涨20K
- 杜教筛【莫比乌斯前缀和,欧拉函数前缀和】推导与模板【一千五百字】
猜你喜欢

Leetcode.234 判断回文链表(双指针/快慢指针)

Redis (ten) - Redission principle and practice

实现批量导出功能

Answer these 3 interview questions correctly, and the salary will go up by 20K

Leetcode.24 两两交换链表中的节点(递归)

The relationship between the number of Oracle processes and the number of sessions

ESP8266 +0.96“ I2C OLED 表盘时钟

基于数据驱动故障预测的多台电力设备预测性维护调度

影响小程序开发费用的三个因素!

One book 1922 - table tennis
随机推荐
WPF递归获取窗体中指定控件类型列表
Mysql中事务是什么?有什么用?
QT based on the third day (3) widget, dialog and mainwindow
票房破7.9亿美元,最近这部恐龙爽片你看了吗?
HCIP 第十五天
Solve The problem of Google browser cross-domain has had been blocked by CORS policy: The request The client is not a secure context and The resou
3种实现文本复制功能的方法
A plastic bottle of ocean "fantasy drifting"
【ModelArts系列】华为ModelArts训练yolov3模型(训练管理)
Simple Operations on Sequence
un7.29:Linux——centos中如何安装与配置redis?
新手入门上位机开发 C#语言:PC串口发送数据
一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
【科研工具的使用】A
[3D检测系列-PointRCNN]复现PointRCNN代码,并实现PointRCNN3D目标检测可视化,包含预训练权重下载链接(从0开始以及各种报错的解决方法)
26 basic models in 6 categories that operators must master
还在用命令行看日志?快用Kibana吧,可视化日志分析YYDS
golang的channel实现原理
Hyperchain超块链创始人史兴国接受21世纪经济报道采访,解读上海NFT新规及数藏发展
自定义 View 实现汉字笔顺动画