我想把要插入的数据先查出来,同时把查出来的数据和一些常量一同插入表中,但是执行下面的SQL会报错:
INSERT INTO usermsg_info(msgTitle,msgContent,createTime,sourceUserId,msgType,isRead,msgUrl,targetUserId)
VALUES(
SELECT
c.msgTitle msgTitle, '第三次来,这次又不能成功' msgContent,
'2017-02-22 10:24:00' createTime, 3 sourceUserId,
3 msgType, '0' isRead, c.msgUrl, c.targetUserId
FROM
(SELECT a.blogTitle msgTitle,
concat(concat(a.userId,'/'),concat(a.blogCategoryId,'/'),concat(a.fileName,'')) msgUrl,
b.userid targetUserId
FROM blog_info a,
user_info b
WHERE a.userId = b.userId
AND a.id=29
)c);
报错信息如下:
[Err] 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
c.msgTitle msgTitle, '第三次来,这次又不能成功' msgConten' at line 3
但是单独执行要插入的那个select语句没问题:
SELECT
c.msgTitle msgTitle, '第三次来,这次又不能成功' msgContent,
'2017-02-22 10:24:00' createTime, 3 sourceUserId,
3 msgType, '0' isRead, c.msgUrl, c.targetUserId
FROM
(SELECT a.blogTitle msgTitle,
concat(concat(a.userId,'/'),concat(a.blogCategoryId,'/'),concat(a.fileName,'')) msgUrl,
b.userid targetUserId
FROM blog_info a,
user_info b
WHERE a.userId = b.userId
AND a.id=29
)c
请问这个问题怎么解决?
语法问题,insetintoselect就可以了
selectintofrom或者insertintoselect
楼上正解,insertintoaselect*fromb
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。