
- 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
Add to existing value in MySQL column using CONCAT function?
To understand the concept, let us first create a demo table.
mysql> create table addToExistingValueDemo -> ( -> Instructor_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Instructor_Name varchar(30), -> Instructor_TechnicalSubject text -> ); Query OK, 0 rows affected (0.54 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('John','C,C++'); Query OK, 1 row affected (0.15 sec) mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('Carol','Java,Python'); Query OK, 1 row affected (0.18 sec) mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('Bob','MySQL,SQL Server'); Query OK, 1 row affected (0.15 sec) mysql> insert into addToExistingValueDemo(Instructor_Name,Instructor_TechnicalSubject) values('David','DataStructure'); Query OK, 1 row affected (0.18 sec
Display all records from the table using select statement. The query is as follows −
mysql> select *from addToExistingValueDemo;
The following is the output
+---------------+-----------------+-----------------------------+ | Instructor_Id | Instructor_Name | Instructor_TechnicalSubject | +---------------+-----------------+-----------------------------+ | 1 | John | C,C++ | | 2 | Carol | Java,Python | | 3 | Bob | MySQL,SQL Server | | 4 | David | DataStructure | +---------------+-----------------+-----------------------------+ 4 rows in set (0.00 sec)
Here is the query to add to existing value in MySQL column using CONCAT function
mysql> update addToExistingValueDemo -> set Instructor_TechnicalSubject=concat(Instructor_TechnicalSubject,', Introduction To Algorithm') -> where Instructor_Id=4; Query OK, 1 row affected (0.10 sec) Rows matched: 1 Changed: 1 Warnings: 0
Let us check the table records once again to see the new changes. The query is as follows −
mysql> select *from addToExistingValueDemo;
The following is the output
+---------------+-----------------+------------------------------------------+ | Instructor_Id | Instructor_Name | Instructor_TechnicalSubject | +---------------+-----------------+------------------------------------------+ | 1 | John | C,C++ | | 2 | Carol | Java,Python | | 3 | Bob | MySQL,SQL Server | | 4 | David | DataStructure, Introduction To Algorithm | +---------------+-----------------+------------------------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- How to update field to add value to existing value in MySQL?
- How to add not null constraint to existing column in MySQL?
- How to add column values in MySQL without using aggregate function?
- MySQL CONCAT a specific column value with the corresponding record
- How to add a new column to an existing table using JDBC API?
- How to add column to an existing table in PostgreSQL?
- Getting last value in MySQL group concat?
- How to add column using alter in MySQL?\n
- How to quote values of single column using GROUP_CONCAT and CONCAT with DISTINCT in MySQL?
- How to add +1 to existing MySQL values?
- How to add comment to column in MySQL using Python?
- Add a temporary column with a value in MySQL?
- Add user defined value to a column in a MySQL query?
- What MySQL returns if we pass column name, containing a NULL value, as one of the arguments of CONCAT() function?
- Add data to existing data in a MySQL Database?

Advertisements