I have a MySQL table with an autoincremented primary key, and a column for a person's name, and some data.
Is there a MySQL query where I can insert a new row if the name of the person is unique, but if it's a duplicate name, then I would update that row?
I.e.
ID, Name, Data
1 , Michael, x
2 , Stephen, y
3 , Christopher, z
If I were to add a "Michael" to the database with "qq" data, I would want the database to look like this:
ID, Name, Data
1 , Michael, qq
2 , Stephen, y
3 , Christopher, z
If I were to add "John" with "zz" data, the database would look like this:
ID, Name, Data
1 , Michael, x
2 , Stephen, y
3 , Christopher, z
4 , John, zz
I know of the command, ON DUPLICATE KEY UPDATE, but I only want to update if the name is the same, not if the primary key is the same.
UNIQUE INDEXonName, nothing big to lose.