MySQL INSERT SELECT not Inserting

北战南征 提交于 2021-02-09 07:30:22

问题


I am trying tor un an insert select that looks like this:

INSERT INTO users_extension_usage (userid, extensionid, complete) 
SELECT '3', extensions.id FROM extensions WHERE extensions.folder='definitions', '1'

however it has a problem when I run it in phpMyAdmin that refers to the '1':

#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 ' '1'' at line 2

I have tried many different combinations of SELECT, INSERT etc but I cat see the problem. I have looked at any different posts on here and other forums too but alas most suggest the syntax I am using!

I have tried to set up an SQL Fiddle here: http://sqlfiddle.com/#!9/9f460

Any suggestions for how this might work will be gratefully accepted :)


回答1:


You are missing the third column:

INSERT INTO users_extension_usage(userid, extensionid, complete) 
    SELECT '3', extensions.id, '1' as complete
    FROM extensions
    WHERE extensions.folder = 'definitions';

The '1' belongs in the SELECT statement, not after the WHERE.



来源:https://stackoverflow.com/questions/35762840/mysql-insert-select-not-inserting

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!