Posted inphp / Mysql / Mysqli

how to concat two columns in sql?

MySQL CONCAT() Function

To concatenate two columns in SQL, you can use the CONCAT function. The syntax is as follows:

SELECT CONCAT(column1, column2) AS new_column_name FROM table_name;

In the above syntax, column1 and column2 are the names of the columns you want to concatenate, new_column_name is the name of the new column that will contain the concatenated result, and table_name is the name of the table containing the columns.

For example, if you have a table named employees with columns first_name and last_name, you can concatenate them into a new column called full_name like this:

SELECT CONCAT(first_name, ' ', last_name) AS full_name FROM employees;

This will create a new column called full_name that contains the concatenated values of first_name and last_name, separated by a space.

Note that the CONCAT function can be used to concatenate more than two columns by simply adding additional column names as arguments.

I am Jaydeep Gondaliya , a software engineer, the founder and the person running Pakainfo. I'm a full-stack developer, entrepreneur and owner of Pakainfo.com. I live in India and I love to write tutorials and tips that can help to other artisan, a Passionate Blogger, who love to share the informative content on PHP, JavaScript, jQuery, Laravel, CodeIgniter, VueJS, AngularJS and Bootstrap from the early stage.

Leave a Reply

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

We accept paid guest Posting on our Site : Guest Post Chat with Us On Skype