Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

mysql query to update all values +1 where value is less than 100

Tags:

sql

mysql

I have a table like this:

create table `test` 
(
    `id` bigint(20) NOT NULL AUTO_INCREMENT, 
    `value` smallint (3) NOT NULL,

I am trying to make a mysql query that increment every row in the test table where value is less than 100.

like image 727
ganjan Avatar asked Mar 08 '11 03:03

ganjan


People also ask

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.

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 limit a SQL update query?

Let us now see the syntax to use UPDATE query with limit. UPDATE yourTableName SET column_name='some value'' WHERE column_name1 IN ( SELECT column_name1 FROM ( select column_name1 from yourTableName order by column_name1 asc limit integerValue,integerValue) anyAliasName );

How do you UPDATE an entire column with different values 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.


2 Answers

update test set value=value+1 where value < 100
like image 175
Jim Garrison Avatar answered Nov 02 '22 23:11

Jim Garrison


update table set value = (value + 1) where column <= 100;
like image 40
Mark Makafa Avatar answered Nov 03 '22 00:11

Mark Makafa