
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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)
Advertisements