网站首页 > 知识剖析 正文
接着之前写的一篇文使用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
我是「翎野君」,感谢各位朋友的:点赞、收藏和评论,我们下期见。
- 上一篇: postgresql一些常用命令「一」
- 下一篇: 通过sql注入获取用户名和密码
猜你喜欢
- 2025-05-22 使用sql语句如何快速导入、导出数据
- 2025-05-22 mysql 替换某一个字段中的字符串
- 2025-05-22 HIVE SQL基础语法
- 2025-05-22 面试官灵魂拷问:为什么 SQL 语句不要过多的 join?
- 2025-05-22 比较常见类型漏洞讲解(三):SQL注入(一)
- 2025-05-22 数据库中记录的批量修改
- 2025-05-22 mysql行合并成字段,字段拆分成多行的示例
- 2025-05-22 SQL 将两张包含相同字段和不同字段的表数据合并成一张表
- 2025-05-22 使用 Python 增强 SQL 操作的 5 种方法
- 2025-05-22 科普基础 | 最全的SQL注入总结
- 05-22js日期加减运算函数封装
- 05-22使用JavaScript比较两个日期
- 05-22JS短文:如何确定一个月中有多少天?
- 05-22JavaScript如何获取当前日期和时间
- 05-22js获取当前年月日
- 05-22使用sql语句如何快速导入、导出数据
- 05-22mysql 替换某一个字段中的字符串
- 05-22HIVE SQL基础语法
- 最近发表
- 标签列表
-
- xml (46)
- css animation (57)
- array_slice (60)
- htmlspecialchars (54)
- position: absolute (54)
- datediff函数 (47)
- array_pop (49)
- jsmap (52)
- toggleclass (43)
- console.time (63)
- .sql (41)
- ahref (40)
- js json.parse (59)
- html复选框 (60)
- css 透明 (44)
- css 颜色 (47)
- php replace (41)
- css nth-child (48)
- min-height (40)
- xml schema (44)
- css 最后一个元素 (46)
- location.origin (44)
- table border (49)
- html tr (40)
- video controls (49)