
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How to add +1 to existing MySQL values?
Let us see an example and create a table first.
mysql> create table Add1ToExistingValue -> ( -> Value int -> ); Query OK, 0 rows affected (0.56 sec)
Insert some records in the table using insert command.
The query is as follows
mysql> insert into Add1ToExistingValue values(10); Query OK, 1 row affected (0.12 sec) mysql> insert into Add1ToExistingValue values(13); Query OK, 1 row affected (0.15 sec) mysql> insert into Add1ToExistingValue values(15); Query OK, 1 row affected (0.13 sec) mysql> insert into Add1ToExistingValue values(16); Query OK, 1 row affected (0.14 sec) mysql> insert into Add1ToExistingValue values(20); Query OK, 1 row affected (0.16 sec) mysql> insert into Add1ToExistingValue values(40); Query OK, 1 row affected (0.15 sec) mysql> insert into Add1ToExistingValue values(50); Query OK, 1 row affected (0.11 sec) mysql> insert into Add1ToExistingValue values(55); Query OK, 1 row affected (0.17 sec) mysql> insert into Add1ToExistingValue values(56); Query OK, 1 row affected (0.17 sec)
Display all records from the table using select statement.
The query is as follows
mysql> select *from Add1ToExistingValue;
The following is the output
+-------+ | Value | +-------+ | 10 | | 13 | | 15 | | 16 | | 20 | | 40 | | 50 | | 55 | | 56 | +-------+ 9 rows in set (0.00 sec)
Here is the query to add +1 to existing values
mysql> update Add1ToExistingValue set Value=Value+1 where Value >=20; Query OK, 5 rows affected (0.08 sec) Rows matched: 5 Changed: 5 Warnings: 0
Let us check the table records from the table using select statement.
The query is as follows
mysql> select *from Add1ToExistingValue;
The following is the output
+-------+ | Value | +-------+ | 10 | | 13 | | 15 | | 16 | | 21 | | 41 | | 51 | | 56 | | 57 | +-------+ 9 rows in set (0.00 sec)
- Related Articles
- How can we add columns with default values to an existing MySQL table?
- How to add columns to an existing MySQL table?
- How to add current date to an existing MySQL table?
- How to add not null constraint to existing column in MySQL?
- How to update field to add value to existing value in MySQL?
- Shifting values of rows in MySQL to change the existing id values for existing rows?
- Add data to existing data in a MySQL Database?
- How to add columns at specific position in existing table in MySQL?
- Add to existing value in MySQL column using CONCAT function?
- How can we add multiple columns, with single command, to an existing MySQL table?
- How to add a random number between 30 and 300 to an existing field in MySQL?
- How to add column to an existing table in PostgreSQL?
- MySQL SUM function to add decimal values
- How to add/append content to an existing file using Java?
- How to add new value to an existing array in JavaScript?

Advertisements