2015-02-11 46 views
1

mysql查詢有什麼不對?

INSERT INTO lm_empleavetypemodelmap(leavetypeid,userid) 
VALUES(1682,"b0c6c81f-a20a-4daa-9038-831478d8e11b") 
WHERE lm_empleavetypemodelmap.userid NOT IN 
    (SELECT lm_empleavetypemodelmap.userid 
    FROM lm_empleavetypemodelmap 
    WHERE lm_empleavetypemodelmap.leavetypeid = 1683) 

[錯誤] 1064 - 你在你的SQL語法錯誤;檢查對應於你的MySQL服務器版本正確的語法使用近1行

回答

1

「WHERE lm_empleavetypemodelmap.userid NOT IN(選擇lm_empleavetypemodelmap.user」你不values使用where手冊。也許東西在結束僅僅是偶然的垃圾,你只是想:

INSERT INTO lm_empleavetypemodelmap(leavetypeid, userid) 
    SELECT 1682, 'b0c6c81f-a20a-4daa-9038-831478d8e11b'; 

或者,那看起來很奇怪對我說:

INSERT INTO lm_empleavetypemodelmap(leavetypeid, userid) 
    SELECT 1682, 'b0c6c81f-a20a-4daa-9038-831478d8e11b' 
    WHERE NOT EXISTS (SELECT 1 FROM lm_empleavetypemodelmap WHERE leavetypeid = 1683) 

也就是說,插件ert 1682,如果1683不存在。通常你關心被插入的值,而不是下一個值。