MySQL Concat Multiple Rows Into A Single Row
Concat Multiple Rows Into A Single Row is less needy thing while querying. sometimes we have an easy solution for a complex problems. This is also like that, You might need to combine few rows for a single column, which is more complicated until you came to know about
GROUP_CONCAT. Let’s code our query with
Our situation will be like this, We have two kind of choices,
- Within the table,
- With Other table
Within the Table
Within a table you can query simply with single table information’s like the below one.
SELECT ID, GROUP_CONCAT(tags SEPARATOR ', ') FROM Users_tags GROUP BY ID
While the above query executed the
tags of an user will be combined in comma separated field.
With Other Table
That’s also so simple, only thing is to put your query in detail.
SELECT usr.ID, usr.email, GROUP_CONCAT(tag.name SEPARATOR ', ') , usr.status FROM `Users`as usr, `Users_tags` as tag WHERE usr.ID = tag.usr_id GROUP BY usr.ID ORDER BY usr.ID DESC
Query collects fields from two tables and combine one. If you wish to get information’s about MySQL
Concat Multiple Columns into One.
Subscribe me to get more updates and tutorials regarding Web design and Development shortcuts and tips. And also follow me on social medias to get more updates from me.