MySQL Duplicate key entry in UPDATE

I have an index uniquein a column with a name label, but for some strange reason why I am trying to update, for example:

UPDATE books SET label = 'foo bar', title = 'something new', modified = UTC_TIMESTAMP();

And there already exists a line with the label = 'foo bar', these are errors:

 #1062 - Duplicate entry 'foo bar' for key 'label'

How to make MySQL do an update? This should not break, because technically there is another line with the key foo bar.

Thank.

+5
source share
1 answer

This SQL query tries to update each entry in the book table with these values ​​because you do not have a WHERE clause. Its failure, because you can only have one entry with this label value, but the query wants to set everything for it.

, , . , . .

+9

All Articles