我試圖將新用戶如果用戶表中不存在的,我想這個查詢,但收到錯誤:MySQL的:插入其中不存在
INSERT INTO USER (name,email)
VALUES ('John','[email protected]')
WHERE NOT EXISTS
(SELECT id FROM USER WHERE email = '[email protected]')
如果不存在如何插入用戶?
錯誤:
#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 id from user where email = '[email protected]')' at line 5
感謝,
什麼是錯誤? – 2014-09-23 13:12:32
MySQL服務器版本爲正確的語法使用附近'哪裏不存在(從用戶選擇ID,其中電子郵件='[email protected]')' – mwafi 2014-09-23 13:14:30
爲什麼不使用IF語句只執行INSERT語句給定條件?... – ne1410s 2014-09-23 13:15:55