
- 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
Subtracting a number from a single MySQL column value?
For this, just update the table and subtract. Let us first create a table −
mysql> create table DemoTable1372 -> ( -> Value int -> ); Query OK, 0 rows affected (0.77 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1372 values(500); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1372 values(100); Query OK, 1 row affected (0.24 sec) mysql> insert into DemoTable1372 values(900); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1372 values(1000); Query OK, 1 row affected (0.32 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1372;
This will produce the following output −
+-------+ | Value | +-------+ | 500 | | 100 | | 900 | | 1000 | +-------+ 4 rows in set (0.00 sec)
Following is the query to subtract a number from a single MySQL column value −
mysql> update DemoTable1372 set Value=Value-50 where Value=900; Query OK, 1 row affected (0.52 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1372;
This will produce the following output −
+-------+ | Value | +-------+ | 500 | | 100 | | 850 | | 1000 | +-------+ 4 rows in set (0.00 sec)
- Related Articles
- How to update a MySQL column by subtracting a value with some conditions?
- Updating only a single column value in MySQL?
- Update only a single column value in MySQL
- Selecting a value in custom order from another column in a MySQL table with a single query
- Get the highest score value from a single column and the greatest from two columns in MySQL
- Subtracting a day in MySQL
- Fetch a single ordered date from a column with MySQL LIMIT
- Get only a single value from a specific MySQL row?
- How to count the number of occurrences of a specific value in a column with a single MySQL query?
- How to display a single quote text as a column value in MySQL?
- Fetch the maximum value from a MySQL column?
- MySQL select only a single value from 5 similar values?
- Replace only a specific value from a column in MySQL
- Find maximum value from a VARCHAR column in MySQL
- Get the count of duplicate values from a single column in MySQL?

Advertisements