

- 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
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 Questions & Answers
- Counting different distinct items in a single MySQL query?
- MySQL query to increase item value price for multiple items in a single query?
- Return only a single row from duplicate rows with MySQL
- Comparing two columns in a single MySQL query to get one row?
- MongoDB inverse of query to return all items except specific documents?
- How to set all values in a single column MySQL Query?
- Write a single MySQL query to return the ID from the corresponding row which is a NOT NULL value
- Selecting a single row in MySQL?
- How to query all items in MongoDB?
- MySQL query to list all the items in a group in one record?
- MySQL LIMIT to select a single row
- Can we update a row with the highest ID in a single MySQL query?
- MySQL query to delete row
- MySQL query to get the highest value from a single row with multiple columns
- Make all column names lower case in MySQL with a single query
Advertisements