- 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
Updating a MySQL table row column by appending a value from user defined variable?
Let us first create a table −
mysql> create table DemoTable1349 -> ( -> ProductId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ProductPrice int -> ); Query OK, 0 rows affected (0.71 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1349(ProductPrice) values(7644); Query OK, 1 row affected (0.28 sec) mysql> insert into DemoTable1349(ProductPrice) values(90843); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable1349(ProductPrice) values(9083); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1349(ProductPrice) values(10000); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1349;
This will produce the following output −
+-----------+--------------+ | ProductId | ProductPrice | +-----------+--------------+ | 1 | 7644| | 2 | 90843| | 3 | 9083| | 4 | 10000| +-----------+--------------+ 4 rows in set (0.00 sec)
Following is the query to update MySQL table row column. At first, we have set a user-defined variable, which we will append later −
mysql> set @AppendValue:=500; Query OK, 0 rows affected (0.00 sec) mysql> update DemoTable1349 set ProductPrice=ProductPrice+@AppendValue where ProductId=4; Query OK, 1 row affected (0.13 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table records once again −
mysql> select * from DemoTable1349;
This will produce the following output −
+-----------+--------------+ | ProductId | ProductPrice | +-----------+--------------+ | 1 | 7644| | 2 | 90843| | 3 | 9083| | 4 | 10500| +-----------+--------------+ 4 rows in set (0.00 sec)
- Related Articles
- MySQL ORDER BY with numeric user-defined variable?
- Add user defined value to a column in a MySQL query?
- In MySQL, why a client cannot use a user-defined variable defined by another client?
- Select into a user-defined variable with MySQL
- Set user-defined variable with table name in MySQL prepare statement?
- How can we store a value in user-defined variable?
- Perform MySQL SELECT INTO user-defined variable
- How can I return a record from a table nearest to a user-defined variables value in MySQL?
- Updating only a single column value in MySQL?
- Increment multiple Timestamp values by setting the incremented value in a user-defined variable in SQL
- Updating a MySQL table with values from another table?
- Set custom messages by working with MySQL IF Statements and SELECT in a user-defined variable
- Show a MySQL user-defined variables values in the result table?
- How Can we permanently define user-defined variable for a client in MySQL?
- Sort a MySQL table column value by part of its value?

Advertisements