How can CONCAT() function be applied on columns of MySQL table?


We can use CONCAT() function to combine the values of two or more columns. In this case, the arguments of the CONCAT() functions would be the name of the columns. For example, suppose we have a table named ‘Student’ and we want the name and address of the student collectively in one column then the following query can be written −

mysql> Select Id, Name, Address, CONCAT(ID,', ',Name,', ', Address)AS 'ID, Name,
Address' from Student;
+------+---------+---------+--------------------+
| Id   | Name    | Address | ID, Name, Address  |
+------+---------+---------+--------------------+
| 1    | Gaurav  | Delhi   | 1, Gaurav, Delhi   |
| 2    | Aarav   | Mumbai  | 2, Aarav, Mumbai   |
| 15   | Harshit | Delhi   | 15, Harshit, Delhi |
| 20   | Gaurav  | Jaipur  | 20, Gaurav, Jaipur |
+------+---------+---------+--------------------+
4 rows in set (0.00 sec)

Updated on: 30-Jan-2020

100 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements