According to the docs:
If [columns
aandbare] unique, theINSERTis equivalent to thisUPDATEstatement instead:UPDATE table SET c=c+1 WHERE a=1 OR b=2 LIMIT 1;If
a=1 OR b=2matches several rows, only one row is updated. In general, you should try to avoid using anON DUPLICATE KEY UPDATEclause on tables with multiple unique indexes.
This is fair enough, but what if I have this as the only key:
PRIMARY KEY (`a`,`b`)
Since the duplicate key is dependant on both fields simultaneously, would the update reliably affect the specific row where the duplicate occurs, or does it do the same as if the fields were individually unique?
If the on duplicate concerns a column witch is define as unique or primary, or the SAME set of columns defined in a unique or primary key, an insert … on duplicate update … statement will update the row where ALL the columns in this PK or unique key have the same values.
To answer your comment on G-Nugget answer, only the row 2 will be updated.
Hope that helps 😉