Let's say I created the following table:
CREATE TABLE `my_table` (
num1 INT PRIMARY KEY,
num2 INT,
num3 INT
) NGINE=InnoDB DEFAULT CHARSET=utf8;
Let's also say that I want to insert a new row to table, and if the new row has the same primary key as one of the existing rows in the table, I want the new row to override the correspondent row.
Currently, the following SQL query will do the job:
INSERT INTO my_table (num1, num2, num3) VALUES (1, 2, 3)
ON DUPLICATE KEY UPDATE num1 = num1, num2 = num2, num3 = num3;
The problem with this query is that it's cumbersome. Imagine a table with 20 columns. I'll have to write again all column names.
Do you know any elegant way to make this happen?