
- 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 all the columns in a single new column with MySQL
Let us first create a −
mysql> create table DemoTable1396 -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(40), -> Age int -> ); Query OK, 0 rows affected (0.93 sec)
Insert some records in the table using insert −
mysql> insert into DemoTable1396(Name,Age) values('Chris',21); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1396(Name,Age) values('David',24); Query OK, 1 row affected (0.34 sec) mysql> insert into DemoTable1396(Name,Age) values('Bob',26); Query OK, 1 row affected (0.40 sec)
Display all records from the table using select −
mysql> select * from DemoTable1396;
This will produce the following output −
+----+-------+------+ | Id | Name | Age | +----+-------+------+ | 1 | Chris | 21 | | 2 | David | 24 | | 3 | Bob | 26 | +----+-------+------+ 3 rows in set (0.00 sec)
Following is the query to concatenate columns in a single new column −
mysql> select Id,Name,Age, concat(Id,Name,Age) as AllColumns from DemoTable1396;
This will produce the following output −
+----+-------+------+------------+ | Id | Name | Age | AllColumns | +----+-------+------+------------+ | 1 | Chris | 21 | 1Chris21 | | 2 | David | 24 | 2David24 | | 3 | Bob | 26 | 3Bob26 | +----+-------+------+------------+ 3 rows in set (0.00 sec)
- Related Articles
- How to concatenate all values of a single column in MySQL?
- Concatenate date and time from separate columns into a single column in MySQL
- Concatenate multiple rows and columns in a single row with MySQL
- MySQL query to get the length of all columns and display the result in a single new column?
- Concatenate the column values with separate text in MySQL and display in a single column
- How to concatenate all columns in MySQL?
- MySQL query to combine two columns in a single column?
- How to concatenate two column values into a single column with MySQL. The resultant column values should be separated by hyphen
- Make all column names lower case in MySQL with a single query
- Select distinct values from three columns and display in a single column with MySQL
- Divide numbers from two columns and display result in a new column with MySQL
- Select multiple columns and display in a single column in MySQL?
- Concatenate two columns in MySQL?
- How to separate last name and first names in single column into two new columns in MySQL?
- Set all the columns of a MySQL table to a particular value with a single query

Advertisements