网站首页 > 技术文章 正文
接着之前写的一篇文使用Mysql中的concat函数或正则匹配来快速批量生成用于执行的sql语句
做什么事情
更新book_borrow表,设置其中的student_name为student表中的name,关联条件为book_borrow.student_id = student_id
student表
book_borrow表
几种不同的更新方式
保留原表数据的更新
只会更新student表中有的数据,student表中查不到的数据,在book_borrow表中还保持不变,不会更新,相当于内连接
update book_borrow br,student st set br.student_name = st.name where br.student_id = st.id;
全部以右表数据为准
更新结果以student的查询结果为准,student中没有查到的记录会全部被更新为null 相当于外连接
update book_borrow br set student_name = (select name from student where id = br.student_id);
update book_borrow br left join student st on br.student_id = st.id set br.student_name = st.name;
将一张表的查询结果插入到另外一张表中
insert select :将一条select语句的结果插入到表中
-- insert into 表名1 (列名) select (列名) from 表名2 ;
insert into tableA(columnA) select columnA from tableB where id=1
我是「翎野君」,感谢各位朋友的:点赞、收藏和评论,我们下期见。
猜你喜欢
- 2025-01-23 顺丰科技 Hudi on Flink 实时数仓实践
- 2025-01-23 AI大模型实战篇:AI Agent设计模式-Plan and Execute
- 2025-01-23 Win10 TH2企业版ISO镜像上线VLSC批量授权服务中心
- 2025-01-23 MySQL常用语句(mysql常用语句50条)
- 2025-01-23 Doris未来会一统江湖吗(doris未来会一统江湖吗为什么)
- 2025-01-23 Java基础教程:k8s快速入门(k8s jmap)
- 2025-01-23 SQL审核优化建议(sql 审核)
- 2025-01-23 一文帮你搞定对MySQL中View视图的所有需求
- 2025-01-23 慢 SQL 分析与优化(慢sql分析工具)
- 2025-01-23 一文看懂MySQL如何判断InnoDB表是独立表空间还是共享表空间
- 02-21走进git时代, 你该怎么玩?_gits
- 02-21GitHub是什么?它可不仅仅是云中的Git版本控制器
- 02-21Git常用操作总结_git基本用法
- 02-21为什么互联网巨头使用Git而放弃SVN?(含核心命令与原理)
- 02-21Git 高级用法,喜欢就拿去用_git基本用法
- 02-21Git常用命令和Git团队使用规范指南
- 02-21总结几个常用的Git命令的使用方法
- 02-21Git工作原理和常用指令_git原理详解
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)