REPLACE INTO will be the solution; it uses UNIQUE INDEX to replace or insert something.
REPLACE INTO yourTable SET column = value;
Remember that this works differently than you might expect, REPLACE is literal. First, it checks to see if there is a UNIQUE INDEX collision that would prevent INSERT , it deletes ( DELETE ) all the rows that collide, and then the INSERT line you gave it.
This, for example, leads to subtle issues like triggers that don't fire (because they check for an update that never happens), or the values โโrevert to their default values โโ(because you have to specify all the values).
Bobby source share