Concatenate Multiple Columns in MySQL

in this tutorial, We ll concatenate two or multiple columns in MySQL.We will select the values and concat multiple columns using MySQL inbuilt method.

It can also achieve same thing using programmatically. You need to select columns fields value separately from MySQL Table and store their values in the single variable after concat their values.

Case 1: I am assuming, We have firstname, lastname column within our DataBase Table.Concatenate firstname, lastname columns values in a single string form.

There are two functions for doing this –

  • CONCAT
  • CONCAT_WS

Above function work for concate multiple columns :

CONCAT

This function is used to concatenate multiple columns or strings into a single one. The method arguments are separated by a comma.

Syntax –

MySQL Query to Concatenate table Columns

CONCAT_WS

The CONCAT_WS() function is used add multiple string values and makes them a single string value.The main difference between CONCAT() and CONCAT_WS() is that we can define separator. It also let you define separator ( ” “, “, “, ” – “, etc.).

Syntax –

Example concatenate Using CONCAT_WS()

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.