我在堆栈中搜索,但没有一个达到最终答案。我的查询是这样的:
INSERT INTO用户(用户名,频率,自动发送) VALUES('feri2','3','1') 不存在的地方(SELECT * FROM WHERE username ='feri2')
运行时,我收到语法分析错误:
SQLSTATE[42000]: Syntax error or access violation: 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 'WHERE NOT EXISTS ( SELECT * FROM user WHERE username='feri2')' at line 1
我不知道该如何解决,问题出在哪里?
您需要稍微更改语法,请尝试以下操作:
INSERT INTO user (username,frequence,autoSend) SELECT * FROM (SELECT 'feri2','3','1') AS `values` WHERE NOT EXISTS ( SELECT username FROM user WHERE username='feri2' ) LIMIT 1;