Languages
[Edit]
EN

MySQL - concatenate multiple columns into one

0 points
Created by:
Mohammad-Oneal
327

In this article, we would like to show you how to concatenate multiple columns into one in MySQL.

Quick solution:

Practical example

Edit

To show how to combine multiple columns into one, we will use the following table:

MySQL - example data used to concatenate columns
MySQL - example data used to concatenate columns

Note:

At the end of this article you can find database preparation SQL queries.

Example 1 - using CONCAT()

Edit

In this example, we will concatenate name and surname columns into one - full_name using empty string (' ') as a separator. Then we will combine the rest of the columns into the second one - address using commas (', ') as separators.

Note:

Go to the next example to see how to specify the separator (such as ', ') only once when you want to concatenate many columns.

Query:

Output:

MySQL - concatenate multiple columns into one - result
MySQL - concatenate multiple columns into one - result

Example 2 - using CONCAT_WS()

Edit

In this example, we will concatenate country, city and street columns into one - address, using CONCAT_WS() function.

Query:

Output:

MySQL - concatenate multiple columns into one using CONCAT_WS - result
MySQL - concatenate multiple columns into one using CONCAT_WS - result

Database preparation

Edit

create_tables.sql file:

insert_data.sql file:

Alternative titles

  1. MySQL - combine multiple columns into one
1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.

MySQL - Problems

MySQL - concatenate multiple columns into one
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join