- 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
How to concatenate strings from different columns and an additional string using a MySQL query?
Let us first create a table −
mysql> create table DemoTable ( FirstName varchar(100), LastName varchar(100) ); Query OK, 0 rows affected (0.76 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('Chris','Brown'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable values('Adam','Smith'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Carol','Taylor'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable values('David','Miller'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | Chris | Brown | | Adam | Smith | | Carol | Taylor | | David | Miller | +-----------+----------+ 4 rows in set (0.00 sec)
Following is the query to perform concatenation. Here, we have FirstName and LastName. With that an additional string is also concatenated in the beginning for all the string values −
mysql> select concat('Hello ',FirstName,' ',LastName) from DemoTable;
This will produce the following output −
+-----------------------------------------+ | concat('Hello ',FirstName,' ',LastName) | +-----------------------------------------+ | Hello Chris Brown | | Hello Adam Smith | | Hello Carol Taylor | | Hello David Miller | +-----------------------------------------+ 4 rows in set (0.00 sec)
- Related Articles
- Concatenate columns from different tables in MySQL
- How to concatenate strings using both GROUP_CONCAT() and CONCAT() in the same MySQL query?
- MySQL query to separate and select string values (with hyphen) from one column to different columns
- How to concatenate MySQL distinct query results into a string?
- How to concatenate all columns in MySQL?
- Different ways to concatenate Strings in Java
- MySQL query to copy records from one table to another with different columns
- How to concatenate two strings using Java?
- How MySQL stored GENERATED COLUMNS are different from MySQL virtual GENERATED COLUMNS?
- Concatenate date and time from separate columns into a single column in MySQL
- Count two different columns in a single query in MySQL?
- Can MySQL concatenate strings with ||?
- MySQL query to calculate the days between two dates from different columns but similar rows
- How to merge queries in a single MySQL query to get the count of different values in different columns?
- MySQL query to sum the values of similar columns from two different tables for a particular ID

Advertisements