网站首页 > 博客文章 正文
接着之前写的一篇文使用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
我是「翎野君」,感谢各位朋友的:点赞、收藏和评论,我们下期见。 ?
- 上一篇: MySQL完整复制表到另一个新表
- 下一篇: MySQL插入数据
猜你喜欢
- 2024-12-03 MySQL INSERT 有哪4种形态?
- 2024-12-03 如何使用 MySQL 数据库进行数据迁移?
- 2024-12-03 MySQL 4种导入数据的方法
- 2024-12-03 mysql 如何一次性导入多个.sql文件
- 2024-12-03 一条简单的更新语句,MySQL是如何加锁的?
- 2024-12-03 怎么把excel导入mysql?
- 2024-12-03 MySQL插入数据
- 2024-12-03 MySQL完整复制表到另一个新表
你 发表评论:
欢迎- 最近发表
- 标签列表
-
- powershellfor (55)
- messagesource (56)
- aspose.pdf破解版 (56)
- promise.race (63)
- 2019cad序列号和密钥激活码 (62)
- window.performance (66)
- qt删除文件夹 (72)
- mysqlcaching_sha2_password (64)
- ubuntu升级gcc (58)
- nacos启动失败 (64)
- ssh-add (70)
- jwt漏洞 (58)
- macos14下载 (58)
- yarnnode (62)
- abstractqueuedsynchronizer (64)
- source~/.bashrc没有那个文件或目录 (65)
- springboot整合activiti工作流 (70)
- jmeter插件下载 (61)
- 抓包分析 (60)
- idea创建mavenweb项目 (65)
- vue回到顶部 (57)
- qcombobox样式表 (68)
- vue数组concat (56)
- tomcatundertow (58)
- pastemac (61)
本文暂时没有评论,来添加一个吧(●'◡'●)