大家好,又见面了,我是你们的朋友全栈君。
将一张表的数据插入两外张表
以表B的数据插入表A, 表B有多少符合条件的数据, 表A就插入多少条数据
如表B符合条件有10条数据,表A也会添加10条数据
case 1
两张表的结构完全一样
insert into tableA select * from tableB
case 2,
两张表的结构不一样,只获取表B中符合条件的一些列的数据
insert into tableA (name,age) select b.studentname, b.age from tableB b where b.id>30
case 3,
两种表的结构不一样,需要获取表B中的符合条件的一些列的数据,还要某些列的特定数据
如需要在表A的列添加老师,学校,值是 ‘陈大文’,‘光明中学’,而表B没有老师,学校列,那么可以以固定值出现在表B输出中
insert into tableA (name,age,teacher,school) select b.studentname, b.age,’陈大文’,‘光明中学’ from tableB b where b.id>30
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/160965.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有