LMSouq
database Open

Insert into a MySQL table or update if exists

KE
Keshan
1 month ago
3 views
Problem Description
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: ```sql INSERT INTO table_name (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.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base