 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we combine the values of two or more columns of MySQL table?
For combining the values of two or more columns of MySQL table, we can use CONCAT() string function. Basically, MySQL CONCAT() function is used to combine two or more strings.
Syntax
CONCAT(String1,String2,…,StringN)
Here, the arguments of CONCAT functions are the strings that need to be combined.
Example
mysql> select CONCAT('Ram','is','a','good','boy') AS Remarks; +---------------+ | Remarks       | +---------------+ | Ramisagoodboy | +---------------+ 1 row in set (0.00 sec) Similarly, we can use CONCAT() function to combine the values of two or more 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)
Advertisements
 