- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Combine multiple text records to one in MySQL
To combine multiple text records, use GROUP_CONCAT(). Let us first create a table −
mysql> create table DemoTable1611 -> ( -> Value text -> ); Query OK, 0 rows affected (0.86 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1611 values('John'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1611 values('is'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1611 values('learning'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable1611 values('Java'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable1611 values('with'); Query OK, 1 row affected (0.13 sec) mysql> insert into DemoTable1611 values('MySQL Database'); Query OK, 1 row affected (0.12 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1611;
This will produce the following output −
+----------------+ | Value | +----------------+ | John | | is | | learning | | Java | | with | | MySQL Database | +----------------+ 6 rows in set (0.00 sec)
Following is the query to combine multiple text records −
mysql> select group_concat(Value separator ' ') from DemoTable1611;
This will produce the following output
+-------------------------------------------+ | group_concat(Value separator ' ') | +-------------------------------------------+ | John is learning Java with MySQL Database | +-------------------------------------------+ 1 row in set (0.00 sec)
Advertisements