1

How do I UPDATE a column in a MySQL-table if and only if a row with a corresponding column "id" exists?

Example of my table:

id | name
---------
1  | NULL
2  | NULL

Example of my data (CSV):

1, Peter
2, Martin
3, Bob

I want Peter and Martin in the table. But I want Bob to be ignored. My query I came up with looks like this:

"UPDATE table SET name = %s WHERE id = %s"

But what would happen while doing:

"UPDATE table SET name = 3 WHERE id = Bob"

?

1 Answer 1

2

It wouldn't do anything. Your WHERE clause is the conditional. When the condition isn't met, the update doesn't occur.

Sign up to request clarification or add additional context in comments.

1 Comment

That means it is save to run the code then. Thanks for your response!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.