Basically, I have a table called document which contains a column named as “host”. I have created another column named as “rev_host” and all I want is to store the reversed strings from “host” to “rev_host”. For example, if the “host” value is “www.cmu.edu”, I want to save “ude.umc.www” to “rev_host”. I then use a statement
INSERT INTO document (rev_host) SELECT REVERSE(host) from document;
This statement throws the 1062 error:
ERROR 1062 (23000): Duplicate entry '' for key 2
What is the problem of this statement? If I cannot insert in this way. What is the right way to perform this insertion?
Your query inserts a whole bunch of new lines in the table, thereby introducing duplicate keys. if you want to update just one column and keep your previous entries use
UPDATEinstead: