250

How to set multiple columns of a table using update query in mysql?

0

3 Answers 3

415

Just add parameters, split by comma:

UPDATE tablename SET column1 = "value1", column2 = "value2" ....

See also: mySQL manual on UPDATE

2
  • 1
    Is it possible to add where clause at the end for both columns?
    – 71GA
    Sep 22, 2017 at 17:33
  • 1
    @71GA I don't think so. That sounds like something you'd need two different statements for.
    – Pekka
    Sep 22, 2017 at 22:18
86
UPDATE some_table 
   SET this_column=x, that_column=y 
   WHERE something LIKE 'them'
7

Let's take an example where you have a people table and you would like to update the age and the name column for the person with id equals to 5. The query will look like this:

UPDATE people SET age = 34, name = "John" WHERE id = 5

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.