I'm trying to create more robust MySQL
Queries and learn in the process. Currently I'm having a hard time trying to grasp the ON DUPLICATE KEY
syntax and possible uses.
I have an INSERT
Query that I want to INSERT
only if there is no record with the same ID
and name, otherwise UPDATE
. ID
and name are not UNIQUE
but ID
is indexed.ID
isn't UNIQUE
because it references another record from another table and I want to have multiple records in this table that reference that one specific record from the other table.
How can I use ON DUPLICATE KEY
to INSERT
only if there is no record with that ID
and name already set else UPDATE
that record?
I can easily achieve this with a couple of QUERIES
and then have PHP
do the IF
ELSE
part, but I want to know how to LIMIT
the amount of QUERIES
I send to MySQL
.