
- 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
MySQL query to return all items in a single row
For this, use GROUP_CONCAT(). Let us first create a table−
mysql> create table DemoTable1355 -> ( -> Location text -> ); Query OK, 0 rows affected (0.57 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1355 values('E:'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1355 values('AllPrograms'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable1355 values('ChatApplicationInJava'); Query OK, 1 row affected (0.38 sec) mysql> insert into DemoTable1355 values('MainFolder'); Query OK, 1 row affected (0.23 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1355;
This will produce the following output −
+-----------------------+ | Location | +-----------------------+ | E: | | AllPrograms | | ChatApplicationInJava | | MainFolder | +-----------------------+ 4 rows in set (0.00 sec)
Here is the query to return all items in one row −
mysql> select group_concat(Location separator '/') from DemoTable1355;
This will produce the following output −
+-------------------------------------------------+ | group_concat(Location separator '/') | +-------------------------------------------------+ | E:/AllPrograms/ChatApplicationInJava/MainFolder | +-------------------------------------------------+ 1 row in set (0.00 sec)
- Related Articles
- Counting different distinct items in a single MySQL query?
- MySQL query to increase item value price for multiple items in a single query?
- Comparing two columns in a single MySQL query to get one row?
- Write a single MySQL query to return the ID from the corresponding row which is a NOT NULL value
- Return only a single row from duplicate rows with MySQL
- How to set all values in a single column MySQL Query?
- MongoDB inverse of query to return all items except specific documents?
- MySQL query to list all the items in a group in one record?
- MySQL query to return multiple row records with AND & OR operator
- Can we update a row with the highest ID in a single MySQL query?
- Selecting a single row in MySQL?
- MySQL LIMIT to select a single row
- How to query all items in MongoDB?
- Make all column names lower case in MySQL with a single query
- MySQL query to delete row

Advertisements