INSERT doesn't allow WHERE
in the syntax.
What you can do: create a UNIQUE INDEX
on the field which should be unique (name
), then use either:
INSERT
(and handle the error if the name already exists)INSERT IGNORE
(which will INSERT ... ON DUPLICATE KEY UPDATE
(which will execute the UPDATE
at the end if name already exists, see documentation)