INSERT INTO users(name, age)
VALUES('姚明', 25), ('比尔.盖茨', 50), ('火星人', 600);
上面的INSERT 语句向users表中连续插入了3条记录。值得注意的是,上面的INSERT语句中的VALUES后必须每一条记录的值放到一对(…)中,中间使用","分割。假设有一个表table1
CREATE TABLE table1(n INT);
如果要向table1中插入5条记录,下面写法是错误的:
INSERT INTO table1 (i) VALUES(1,2,3,4,5);
MySQL将会抛出下面的错误
ERROR 1136: Column count doesn't match value count at row 1
而正确的写法应该是这样:
INSERT INTO t able1(i) VALUES(1),(2),(3),(4),(5);
当然,这种写法也可以省略列名,这样每一对括号里的值的数目必须一致,而且这个数目必须和列数一致。如:
INSERT INTO t able1 VALUES(1),(2),(3),(4),(5);
表中的对考
insert
into
vip_prep (
select
vip_cname,vip_mobile,cityCode,disttrict,vip_officetel,offer_id, is_associator,add_time
from
vip_user
where
is_associator
=
0
)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
insert
into
vip_prep(vip_cname,vip_mobile,cityCode,disttrict,vip_officetel,offer_id, is_associator,add_time)(
select
vip_cname,vip_mobile,cityCode,disttrict,vip_officetel,offer_id, is_associator,add_time
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
from
vip_user
where
is_associator
=
0
)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/6810355c2f78c12e91b7997a8e8c583a.gif)
SELECT
vip_cname, vip_mobile, cityCode, disttrict, vip_officetel, offer_id, is_associator, add_time
FROM
vip_user
WHERE
is_associator
=
'
0
'