网站首页 > 教程文章 正文
接着之前写的一篇文使用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-05-02 《JDBC》第14节:JDBC之获取数据库中的表信息和表字段信息
- 2025-05-02 mysql数据库ORDER BY优化总结(为排序使用索引)
- 2025-05-02 无法获取新增ID值问题排查(无法获取iccid什么意思)
- 2025-05-02 MySQL实现字段分割(一行转多行)(mysql 一行变多行)
- 2025-05-02 MySQL批量生成建表语句(mysql怎么批量造数据)
- 2025-05-02 Python mysql批量更新数据(兼容动态数据库字段、表名)
- 2025-05-02 MySQL数据库中,数据量越来越大,有什么具体的优化方案么?
- 2025-05-02 MySQL多行数据合并为一个字段的方法
- 最近发表
- 标签列表
-
- location.href (44)
- document.ready (36)
- git checkout -b (34)
- 跃点数 (35)
- 阿里云镜像地址 (33)
- qt qmessagebox (36)
- md5 sha1 (32)
- mybatis plus page (35)
- semaphore 使用详解 (32)
- update from 语句 (32)
- vue @scroll (38)
- 堆栈区别 (33)
- 在线子域名爆破 (32)
- 什么是容器 (33)
- sha1 md5 (33)
- navicat导出数据 (34)
- 阿里云acp考试 (33)
- 阿里云 nacos (34)
- redhat官网下载镜像 (36)
- srs服务器 (33)
- pico开发者 (33)
- https的端口号 (34)
- vscode更改主题 (35)
- 阿里云资源池 (34)
- os.path.join (33)