
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 Articles
- 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?
- How to include quotes in comma separated column with MySQL?
- 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
- 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
- How to count specific comma separated values in a row retrieved from MySQL database?
- Find integer in text data (comma separated values) with MySQL?
- MySQL query to get string from one column and find its position in another column with comma separated values?
- Fetch records from comma separated values using MySQL IN()?
- MySQL query to select a row which contains same number in a column with set of numbers separated by comma?
- 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?

Advertisements