2016-01-31 231 views
0

我嘗試此請求但出現語法錯誤:插入多條記錄whith where條款

您的SQL語法錯誤;檢查對應於你的MySQL服務器版本使用附近的正確語法手冊 'WHERE fk_competence NOT EXISTS(SELECT fk_competence FROM apo_competence_theme W' 位於第1行

INSERT INTO apo_competence_theme(fk_competence,fk_theme)VALUES(15,11) ,(8,11),(11,11),其中fk_competence NOT EXISTS(SELECT fk_competence FROM apo_competence_theme WHERE fk_theme = 11)

我想插入當記錄並不在此表

THX的存在回答

回答

0

您可能需要使用INSERT INTO - SELECTLEFT JOINWHERE,例如:

insert into apo_competence_theme (fk_competence, fk_theme) 
select to_insert.* from 
(
    select 5 fk_competence, 11 fk_theme union 
    select 8, 11 union 
    select 11, 11 
) to_insert 
left join apo_competence_theme act on to_insert.fk_theme = act.fk_theme and to_insert.fk_competence = act.fk_competence 
where act.fk_competence is null