向一个表的字段中插入另外一个表的某字段的最大值(自增字段,刚自增的数值),请问此MYSQL语句该怎么写
INSERTINTO`ecs_goods_gallery`(`goods_id`,`img_url`,`img_desc`,`thumb_url`,`img_origin...
INSERT INTO `ecs_goods_gallery` (`goods_id`, `img_url`, `img_desc`, `thumb_url`, `img_original`) VALUES (select max(goods_id) from ecs_goods,'3.jpg', '', '1.jpg', '3.jpg');
一楼的不行,报错
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select max(goods_id),'3.jpg', '', '1.jpg', '3.jpg' from ecs_goods' at line 1
INSERT INTO `ecs_goods_gallery` ( `goods_id` , `img_url` , `img_desc` , `thumb_url` , `img_original` )
VALUES SELECT max( goods_id ) , '3.jpg', '', '1.jpg', '3.jpg'
FROM ecs_goods 展开
一楼的不行,报错
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'select max(goods_id),'3.jpg', '', '1.jpg', '3.jpg' from ecs_goods' at line 1
INSERT INTO `ecs_goods_gallery` ( `goods_id` , `img_url` , `img_desc` , `thumb_url` , `img_original` )
VALUES SELECT max( goods_id ) , '3.jpg', '', '1.jpg', '3.jpg'
FROM ecs_goods 展开
2个回答
展开全部
INSERT INTO `ecs_goods_gallery` (`goods_id`, `img_url`, `img_desc`, `thumb_url`, `img_original`) select max(goods_id)+1 from ecs_goods,'3.jpg', '', '1.jpg', '3.jpg';
问题1:是自增,那么你重复肯定不行,所以要最大ID+1才行
第二,如果insert into 后select了,不用values
问题1:是自增,那么你重复肯定不行,所以要最大ID+1才行
第二,如果insert into 后select了,不用values
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询