

- 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
Display all the column values in a single row separated by comma in MySQL?
For this, use GROUP_CONCAT() and CONCAT(). Let us first create a table −
mysql> create table DemoTable1807 ( Id int ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1807 values(101); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1807 values(102); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1807 values(103); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1807;
This will produce the following output −
+------+ | Id | +------+ | 101 | | 102 | | 103 | +------+ 3 rows in set (0.00 sec)
Here is the query to convert SQL query to MySQL −
mysql> select group_concat(concat('[',Id,']')) from DemoTable1807;
This will produce the following output −
+----------------------------------+ | group_concat(concat('[',Id,']')) | +----------------------------------+ | [101],[102],[103] | +----------------------------------+ 1 row in set (0.00 sec)
- Related Questions & Answers
- Get values from all rows and display it a single row separated by comma with MySQL
- How to display data from a MySQL column separated by comma?
- Searching from a comma separated MySQL column?
- Find specific records from a column with comma separated values in MySQL
- Finding a specific row which has several ids separated by comma in MySQL?
- Insert all the values in a table with a single MySQL query separating records by comma
- Display MySQL Results as comma separated list?
- How to count specific comma separated values in a row retrieved from MySQL database?
- Count values from comma-separated field in MySQL?
- How to concatenate two column values into a single column with MySQL. The resultant column values should be separated by hyphen
- MySQL query to select a row which contains same number in a column with set of numbers separated by comma?
- Fetch records from comma separated values using MySQL IN()?
- Check if the column values are the same among multiple records and set these records in a single row separated by a special character in MySQL
- How to include quotes in comma separated column with MySQL?
- Concatenate the column values with separate text in MySQL and display in a single column
Advertisements