我试试这个requete但是有一个语法错误:
您的SQL语法有错误;查看与您的MySQL服务器版本相对应的手册,以获得正确的语法,使用附近' WHERE fk_competence NOT EXISTS(选择fk_competence来自apo_competence_theme W'在第1行
INSERT INTO apo_competence_theme(fk_competence,fk_theme)VALUES(15,11),(8,11),(11,11)WHERE fk_competence NOT EXISTS(SELECT fk_competence from apo_competence_theme WHERE fk_theme = 11)
我希望在此表中不存在记录时插入
回答
答案 0 :(得分:0)
INSERT INTO语句不支持WHERE子句。
在此处查看有关您的问题的更多详细信息: MySQL Insert Where query
答案 1 :(得分:0)
您可能需要将INSERT INTO
- SELECT
与LEFT JOIN
和WHERE
一起使用,例如:
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