Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update two columns in a MySQL database?

This doesn't work:

UPDATE customers SET firstname="John" AND lastname="Smith" WHERE id=1; 
like image 786
Shields Avatar asked Mar 11 '10 17:03

Shields


People also ask

How do I update only two columns in SQL?

The UPDATE statement in SQL is used to update the data of an existing table in database. We can update single columns as well as multiple columns using UPDATE statement as per our requirement. UPDATE table_name SET column1 = value1, column2 = value2,...

How do I update two columns?

We can update multiple columns by specifying multiple columns after the SET command in the UPDATE statement. The UPDATE statement is always followed by the SET command, it specifies the column where the update is required.

How do you update multiple columns in SQL with different conditions?

To update multiple columns use the SET clause to specify additional columns. Just like with the single columns you specify a column and its new value, then another set of column and values. In this case each column is separated with a column.


1 Answers

Separate values with commas. AND is an logical operator, its place is in WHERE and ON clauses.

UPDATE customers SET firstname="John", lastname="Smith" WHERE id=1; 
like image 164
Tatu Ulmanen Avatar answered Sep 22 '22 23:09

Tatu Ulmanen