- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Decrease a row value by 1 in MySQL?
You can increase and decrease row value by 1 in MySQL using UPDATE command. The syntax is as follows −
UPDATE yourTableName set yourColumnName = yourColumnName-1 where condition;
Let us create a table to decrease row value by 1. The following is the query −
mysql> create table IncrementAndDecrementValue −> ( −> UserId int, −> UserScores int −> ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into IncrementAndDecrementValue values(101,20000); Query OK, 1 row affected (0.13 sec) mysql> insert into IncrementAndDecrementValue values(102,30000); Query OK, 1 row affected (0.20 sec) mysql> insert into IncrementAndDecrementValue values(103,40000); Query OK, 1 row affected (0.11 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from IncrementAndDecrementValue;
The following is the output;
+--------+------------+ | UserId | UserScores | +--------+------------+ | 101 | 20000 | | 102 | 30000 | | 103 | 40000 | +--------+------------+ 3 rows in set (0.00 sec)
Here is the query to decrease the UserScores value by 1 with where condition.
mysql> update IncrementAndDecrementValue set UserScores = UserScores-1 where UserId = 103; Query OK, 1 row affected (0.41 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check whether the value is updated or not. The query is as follows −
mysql> select *from IncrementAndDecrementValue;
The following is the output displaying that we have successfully decremented a row value −
+--------+------------+ | UserId | UserScores | +--------+------------+ | 101 | 20000 | | 102 | 30000 | | 103 | 39999 | +--------+------------+ 3 rows in set (0.00 sec)
- Related Articles
- Increase and decrease row value by 1 in MySQL with Stored Procedure?
- MySQL query to decrease value by 10 for a specific value?
- Updating a MySQL table row column by appending a value from user defined variable?
- MySQL query to decrease the value of a specific record to zero?
- Fix a row value and then ORDER BY DESC rest of the values in MySQL
- SELECT where row value contains string in MySQL?
- In MySQL, how we can get the total value by category in one output row?
- SELECT a row by subtracting dates in WHERE in MySQL?
- MySQL insert a value to specific row and column
- Get only a single value from a specific MySQL row?
- Count the same value of each row in a MySQL column?
- How can I customize value, instead of NULL, of a row by using MySQL IF() function?
- MySQL get hash value for each row?
- Show row with zero value after addition in MySQL?
- Return value from a row if it is NOT NULL, else return the other row value in another column with MySQL

Advertisements