Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Updating multiple values in MySQL

Tags:

sql

mysql

How can I update multiple values in MySQL?

This didn't work:

UPDATE test SET list=0, price= 0.00 cprice= 0.00 WHERE test.id =3232 
like image 581
streetparade Avatar asked Nov 02 '09 16:11

streetparade


People also ask

How do you UPDATE multiple values in a column in SQL?

First, specify the table name that you want to change data in the UPDATE clause. Second, assign a new value for the column that you want to update. In case you want to update data in multiple columns, each column = value pair is separated by a comma (,). Third, specify which rows you want to update in the WHERE clause.

How do I UPDATE all values in a column in MySQL?

To set all values in a single column MySQL query, you can use UPDATE command. The syntax is as follows. update yourTableName set yourColumnName =yourValue; To understand the above syntax, let us create a table.

How do I UPDATE multiple values in MySQL?

MySQL UPDATE command can be used to update multiple columns by specifying a comma separated list of column_name = new_value. Where column_name is the name of the column to be updated and new_value is the new value with which the column will be updated.

Can we UPDATE multiple values 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.


2 Answers

You need to put a comma between the two different values, for example:

UPDATE orders     SET listPrice = 0,        bloggerPrice = 0.00,        customerPrice = 0.00  WHERE orders.id =245745 
like image 52
northpole Avatar answered Oct 22 '22 05:10

northpole


You're missing a comma:

UPDATE orders SET      listPrice = 0,      bloggerPrice = 0.00,      customerPrice = 0.00  WHERE      orders.id = 245745 
like image 29
Greg Avatar answered Oct 22 '22 06:10

Greg