insert into 和select 结合使用

1.语法

insert into 新建表名 (新建表的字段)

select 字段1,字段2,字段3 ······

2.例子

insert into newtb (district,districtid,town,townid,village,villageid)
select infotb.district,infotb.districtid,infotb.town,infotb.townid,infotb.village,dictionary.villageid
from infotb,dictionary
where infotb.village like dictionary.village and infotb.town like dictionary.town and infotb.districtid like dictionary.districtid;

3.select的特殊用法

select 1 from 表名 

查询结果为表内数据个1

select 后边还可以直接跟字符串或数字,查询结果的的对应字段处都是该数字或者字符串。

posted @ 2020-01-02 16:10  StarZhai  阅读(8932)  评论(0编辑  收藏  举报