sql 语句 将一个表中的数据插入到另一个表中

1、insert INTO ns_goods_category (shop_id,category_name,short_name,level) select shop_id,"其他","其他",1 from ns_shop where shop_id >0;
"其他","其他",1
代表插入的表中有的字段而查询的表中没有该字段
insert into 表名 (字段名) select 字段名 from 表名 where 条件 注意:前后两个表中的字段名一致,可以使用该方法

2、update ns_goods g,ns_goods_category c set g.category_id=c.category_id,g.category_id_1=c.category_id where g.shop_id=c.shop_id and g.category_id_1 > 0 and g.shop_id >0;
含义:表示将A表中的数据根据条件修改为B表中的数据
update table1,table2 set table1.字段名=table2.字段名 where table1.(与table2表有关联的字段)=table2.(与table1有关联的字段) and 条件

 

posted @ 2018-08-21 22:14  HTeroPair的博客  阅读(7828)  评论(0编辑  收藏  举报