
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
Update MySQL Table Row Column by Appending 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)
Advertisements