0

i try this requete but a have a syntaxe error :

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 fk_competence NOT EXISTS (SELECT fk_competence FROM apo_competence_theme W' at line 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)

i want to insert when the record don't exist in this table

thx for answer

el tyty
  • 3
  • 2

2 Answers2

0

the INSERT INTO statement doesn't support the WHERE clause.

Look here for more details on your problem: MySQL Insert Where query

Community
  • 1
  • 1
blacksheep_2011
  • 1,083
  • 3
  • 11
  • 22
0

You may need to use INSERT INTO -- SELECT with LEFT JOIN and WHERE, e.g.:

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
Husni
  • 1,045
  • 9
  • 12