
- 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
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 Articles
- 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?
- Find specific records from a column with comma separated values in MySQL
- How to count specific comma separated values in a row retrieved from MySQL database?
- 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
- Searching from a comma separated MySQL column?
- Display MySQL Results as comma separated list?
- MySQL query to select a row which contains same number in a column with set of numbers separated by comma?
- 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
- 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
- Fetch records from comma separated values using MySQL IN()?
- Concatenate the column values with separate text in MySQL and display in a single column
- Display duplicate record as a distinct value with corresponding values as distinct comma separated list in MySQL?

Advertisements