X

Congrats, You are Subscribed to Receive Updates.

MySQL Concat Multiple Rows Into A Single Row


MySQL 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 GROUP_CONCAT.

Our situation will be like this, We have two kind of choices,

  1. Within the table,
  2. 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.

 

commenter

About Varadharaj V

The founder of Kvcodes, Varadharaj V is an ERP Analyst and a Web developer specializing in WordPress(WP), WP Theme development, WP Plugin development, Frontaccounting(FA), Sales, Purchases, Inventory, Ledgers, Payroll & HRM, CRM, FA Core Customization, OpenCart Theme Development, PHP, HTML, CSS, jQuery, Bootstrap development and content SEO.

Comment Below

Your email address will not be published. Required fields are marked *

*

Current ye@r *

Menu

Sidebar

Subscribe E-mail Updates

Congrats, You are Subscribed to Receive Updates.

Advertisement

Category Posts