

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
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 to display data from a MySQL column separated by comma?
You can use GROUP_CONCAT() function from MySQL to display result as a comma separated list. Let us first create a table −
mysql> create table DemoTable ( Value int ); Query OK, 0 rows affected (0.26 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(10); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable values(20); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(30); Query OK, 1 row affected (0.06 sec) mysql> insert into DemoTable values(40); Query OK, 1 row affected (0.07 sec) mysql> insert into DemoTable values(50); Query OK, 1 row affected (0.07 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------+ | Value | +-------+ | 10 | | 20 | | 30 | | 40 | | 50 | +-------+ 5 rows in set (0.00 sec)
Following is the query to display data from a column separated by comma.
mysql> SELECT GROUP_CONCAT(Value) FROM DemoTable;
This will produce the following output −
+---------------------+ | GROUP_CONCAT(Value) | +---------------------+ | 10,20,30,40,50 | +---------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- Searching from a comma separated MySQL column?
- Display all the column values in a single row separated by comma in MySQL?
- Display MySQL Results as comma separated list?
- Get values from all rows and display it a single row separated by comma with MySQL
- Find specific records from a column with comma separated values in MySQL
- How to include quotes in comma separated column with MySQL?
- Count values from comma-separated field in MySQL?
- Count the number of comma’s in every record from a comma-separated value column in MySQL
- Fetch records from comma separated values using MySQL IN()?
- Find integer in text data (comma separated values) with MySQL?
- How to count specific comma separated values in a row retrieved from MySQL database?
- MySQL query to retrieve records from the part of a comma-separated list?
- MySQL query to get a single value from position of comma-separated string?
- How to set a comma separated list as a table in MySQL?
- Finding a specific row which has several ids separated by comma in MySQL?
Advertisements