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:
In my case i created below queries but in the first query if id
1 is already exists and age is already there, after that if you create first query without age
than the value of age
will be none
REPLACE into table SET `id` = 1, `name` = 'A', `age` = 19
for avoiding above issue create query like below
INSERT INTO table SET `id` = '1', `name` = 'A', `age` = 19 ON DUPLICATE KEY UPDATE `id` = "1", `name` = "A",`age` = 19
may it will help you ...