
- 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
Concatenate the column values with separate text in MySQL and display in a single column
Let us first create a table −
mysql> create table DemoTable -> ( -> Id int, -> Name varchar(20) -> ); Query OK, 0 rows affected (0.93 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(101,'Chris'); Query OK, 1 row affected (0.25 sec) mysql> insert into DemoTable values(102,'David'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable values(103,'Robert'); Query OK, 1 row affected (0.16 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output−
+------+--------+ | Id | Name | +------+--------+ | 101 | Chris | | 102 | David | | 103 | Robert | +------+--------+ 3 rows in set (0.00 sec)
Following is the MySQL query to concatenate the column values with separate text −
mysql> select concat('The student id and name is= ', Id , ',' , Name, ' .') from DemoTable;
This will produce the following output −
+---------------------------------------------------------------+ | concat('The student id and name is= ', Id , ',' , Name, ' .') | +---------------------------------------------------------------+ | The student id and name is= 101,Chris . | | The student id and name is= 102,David . | | The student id and name is= 103,Robert . | +---------------------------------------------------------------+ 3 rows in set (0.01 sec)
- Related Articles
- Concatenate date and time from separate columns into a single column in MySQL
- How to concatenate all values of a single column in MySQL?
- How to concatenate two column values into a single column with MySQL. The resultant column values should be separated by hyphen
- Concatenate all the columns in a single new column with MySQL
- Display the sum of positive and negative values from a column in separate columns with MySQL
- Select distinct values from three columns and display in a single column with MySQL
- Store strings in variables and concatenate them to display them in a single column in MYSQL
- Count duplicate ids and display the result in a separate column with MySQL
- MySQL query to count the duplicate ID values and display the result in a separate column
- How to display a single quote text as a column value in MySQL?
- Display all the column values in a single row separated by comma in MySQL?
- How to round MySQL column with float values and display the result in a new column?
- Concatenate some of the column values in a single line with MySQL and prefix a particular string “MR.” to every string
- Select multiple columns and display in a single column in MySQL?
- Concatenate two values from the same column with different conditions in MySQL

Advertisements