Posts

Showing posts from March 5, 2019

Insert into a MySQL table or update if exists

Image
742 220 I want to add a row to a database table, but if a row exists with the same unique key I want to update the row. For example, insert into table (id, name, age) values(1, "A", 19) Let’s say the unique key is id , and in my database there is a row with id = 1 . In that case I want to update that row with these values. Normally this gives an error. If I use insert IGNORE it will ignore the error, but it still won’t update. mysql sql insert-update share | improve this question edited Jan 8 '17 at 13:06 Peter Mortensen 13.7k 19 86 113