{"id":5610,"date":"2024-11-28T07:30:47","date_gmt":"2024-11-28T07:30:47","guid":{"rendered":"https:\/\/ubiq.co\/tech-blog\/?p=5610"},"modified":"2024-11-28T08:49:24","modified_gmt":"2024-11-28T08:49:24","slug":"how-to-concatenate-multiple-mysql-rows-into-one-field","status":"publish","type":"post","link":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/","title":{"rendered":"How to Concatenate Multiple MySQL Rows into One Field"},"content":{"rendered":"\n<p>Often database programmers and administrators need to aggregate data present in different rows of table into a single column. This is commonly required if you have a large table and you want to summarize information present in a single column. In this article, we will learn how to concatenate multiple MySQL rows into one field using group_concat() function.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#How_to_Concatenate_Multiple_MySQL_Rows_into_One_Field\" >How to Concatenate Multiple MySQL Rows into One Field<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#1_Using_group_concat\" >1. Using group_concat()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#2_Using_distinct_keyword\" >2. Using distinct keyword<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#3_Using_order_by_clause\" >3. Using order by clause<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#4_With_concat_and_group_concat\" >4. With concat() and group_concat()<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#Setting_group_concat_max_length\" >Setting group_concat max length<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#Conclusion\" >Conclusion<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_to_Concatenate_Multiple_MySQL_Rows_into_One_Field\"><\/span>How to Concatenate Multiple MySQL Rows into One Field<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>group_concat() is the main function specifically created to concatenate multiple MySQL rows into one field. Here is its syntax.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">SELECT col1, col2, ..., colN,<br>GROUP_CONCAT ( [DISTINCT] col_name1 [ORDER BY clause]  [SEPARATOR str_val] ) <br>FROM table_name GROUP BY col_name2;<\/pre>\n\n\n\n<p>In the above query, we specify the usual column names of table col1, col2, etc. that need not be modified. Then we also include group_concat() function whose result will be another column in query output. In this function, we mention the column name whose values we want to concatenate. Optionally, you can include DISTINCT and ORDER BY keywords inside the function. You can also include a separator character to separate the different values of columns. Then we also add a group by clause to group the rows of the table.<\/p>\n\n\n\n<p>Let us say you have the following sales table.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; create table product(id int, name varchar(10),attribute varchar(255));<br><br>mysql&gt; insert into product(id, name, attribute) <br>       values(1,'A','strong'),(1,'A','durable'),<br>             (2,'B','cheap'),(2,'B','waterproof');<br><br>mysql&gt; select * from product;<br>+------+------+------------+<br>| id   | name | attribute  |<br>+------+------+------------+<br>|    1 | A    | strong     |<br>|    1 | A    | durable    |<br>|    2 | B    | cheap      |<br>|    2 | B    | waterproof |<br>+------+------+------------+<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"1_Using_group_concat\"><\/span>1. Using group_concat()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Let us say you want to combine the various values of attribute column into a single row, for each product. Here is a simple SQL query to do this.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select id, name, group_concat(attribute separator ',') as 'attributes' <br>       from product <br>       group by id,name;<br>+------+------+------------------+<br>| id   | name | attributes       |<br>+------+------+------------------+<br>|    1 | A    | strong,durable   |<br>|    2 | B    | cheap,waterproof |<br>+------+------+------------------+<\/pre>\n\n\n\n<p>In the above query, we have included id and name column in select clause as-is. We have also called group_concat() function on attribute column, and mentioned comma as separator. We have named the result of this column as attributes. Lastly, we have grouped the data by id and name since we want the row values to be combined for each group.<\/p>\n\n\n\n<p>If you do not include GROUP BY clause in the query then all column values will be concatenated into a single string and assigned to the first row of the table.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select id, name, group_concat(attribute separator ',') as 'attributes' <br>       from product;<br>+------+------+---------------------------------+<br>| id   | name | attributes                      |<br>+------+------+---------------------------------+<br>|    1 | A    | strong,durable,cheap,waterproof |<br>+------+------+---------------------------------+<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"2_Using_distinct_keyword\"><\/span>2. Using distinct keyword<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>If there are duplicate values in the column then you can use distinct keyword to combine only duplicate values in them. Let us say you have the following product table.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select * from product order by id, name;<br>+------+------+------------+<br>| id   | name | attribute  |<br>+------+------+------------+<br>|    1 | A    | <strong>strong<\/strong>     |<br>|    1 | A    | durable    |<br>|    1 | A    | attractive |<br>|    1 | A    | <strong>strong<\/strong>     |<br>|    2 | B    | <strong>cheap<\/strong>      |<br>|    2 | B    | waterproof |<br>|    2 | B    | attractive |<br>|    2 | B    | <strong>cheap <\/strong>     |<br>+------+------+------------+<\/pre>\n\n\n\n<p>As you can see, there are duplicate rows in our table. If we try to combine the values of attribute column using group_concat() function, we will get the following result.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select id, group_concat(attribute separator ',') as 'attributes' <br>       from product <br>       group by id;<br>+------+-----------------------------------+<br>| id   | attributes                        |<br>+------+-----------------------------------+<br>|    1 | <strong>strong<\/strong>,durable,attractive,<strong>strong<\/strong>  |<br>|    2 | <strong>cheap<\/strong>,waterproof,attractive,<strong>cheap<\/strong> |<br>+------+-----------------------------------+<\/pre>\n\n\n\n<p>As you can see, the result of group_concat() function contains duplicate values. If you want to avoid this and pick only unique values, then add DISTINCT keyword in group_concat() function.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select id, group_concat(distinct attribute separator ',') as 'attributes' <br>       from product <br>       group by id;<br>+------+-----------------------------+<br>| id   | attributes                  |<br>+------+-----------------------------+<br>|    1 | strong,durable,attractive   |<br>|    2 | cheap,waterproof,attractive |<br>+------+-----------------------------+<\/pre>\n\n\n\n<p>When you use DISTINCT keyword in group_concat() function, it will first pick only the unique values of its column and then it will concatenate the values.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"3_Using_order_by_clause\"><\/span>3. Using order by clause<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>By default, group_concat() concatenates column values in the same order as they appear in original table. Let us say you have the following product table.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select * from product order by id, name;<br>+------+------+------------+<br>| id   | name | attribute  |<br>+------+------+------------+<br>|    1 | A    | strong     |<br>|    1 | A    | durable    |<br>|    1 | A    | attractive |<br>|    2 | B    | cheap      |<br>|    2 | B    | waterproof |<br>|    2 | B    | attractive |<br>+------+------+------------+<\/pre>\n\n\n\n<p>If you use group_concat() to combine values in attribute column for each product name, then you will get the following result.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select id, group_concat(attribute separator ',') as 'attributes' <br>       from product <br>       group by id;<br>+------+-----------------------------+<br>| id   | attributes                  |<br>+------+-----------------------------+<br>|    1 | strong,durable,attractive   |<br>|    2 | cheap,waterproof,attractive |<br>+------+-----------------------------+<\/pre>\n\n\n\n<p>Let us say you want to display the attributes in alphabetical order instead. For this purpose, you can use the order by clause within group_concat() function as shown below.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; select id, group_concat(attribute <strong>order by attribute<\/strong> separator ',') as 'attributes' <br>       from product <br>       group by id;<br>+------+-----------------------------+<br>| id   | attributes                  |<br>+------+-----------------------------+<br>|    1 | attractive,durable,strong   |<br>|    2 | attractive,cheap,waterproof |<br>+------+-----------------------------+<\/pre>\n\n\n\n<p>As you can see, the attribute column&#8217;s values have been sorted alphabetically for each group, before concatenation.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"4_With_concat_and_group_concat\"><\/span>4. With concat() and group_concat()<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>So far, we have seen examples where we concatenate the values of only 1 field. What if you want to combine the values of 2 or more columns? In this case, you will need to use group_concat() function along with <a href=\"https:\/\/www.w3schools.com\/sql\/func_mysql_concat.asp\">concat()<\/a> function. Here is an example to concatenate all values of attribute as well as id columns.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; SELECT GROUP_CONCAT( attributes SEPARATOR '  ') as \"id : attributes\"<br>     FROM (<br>                     SELECT id, CONCAT ( name, ':', GROUP_CONCAT(attribute SEPARATOR', ') )<br>                     as \"attributes\"<br>                     FROM product<br>                     GROUP BY name<br>     ) as emp;<br>+-------------------------------------------------------------------------------+<br>| id : attributes                                                               |<br>+-------------------------------------------------------------------------------+<br>| A:strong, durable, attractive, strong  B:cheap, waterproof, attractive, cheap |<br>+-------------------------------------------------------------------------------+<\/pre>\n\n\n\n<p>In the above query, there are 2 SQL queries. The inner SQL query does a concatenation of attribute column as well as product name column.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt;  SELECT id, CONCAT ( name, ':', GROUP_CONCAT(attribute SEPARATOR', ') )<br>                     as \"attributes\"<br>                     FROM product<br>                     GROUP BY name ;<br>+------+----------------------------------------+<br>| id   | attributes                             |<br>+------+----------------------------------------+<br>|    1 | A:strong, durable, attractive, strong  |<br>|    2 | B:cheap, waterproof, attractive, cheap |<br>+------+----------------------------------------+<\/pre>\n\n\n\n<p>The outer SQL query concatenates the values of attributes column.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">+-------------------------------------------------------------------------------+<br>| id : attributes                                                               |<br>+-------------------------------------------------------------------------------+<br>| A:strong, durable, attractive, strong  B:cheap, waterproof, attractive, cheap |<br>+-------------------------------------------------------------------------------+<\/pre>\n\n\n\n<p>We have used a very simple example in this case for ease of understanding. You can obviously use group by clause in outer SQL query to concatenate values for each group.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Setting_group_concat_max_length\"><\/span>Setting group_concat max length<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>By default, the result of group_concat() column is 1024 bytes. If it is more than then it will be truncated to 1024 bytes. If you want to increase this value, then run the following command for this purpose. Here is the query to increase the limit of group_concat() function&#8217;s result to 2048 bytes.<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">mysql&gt; SET group_concat_max_len = 2048;<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span>Conclusion<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>In this article, we have learnt how to combine column values of multiple rows into single row, using group_concat() function. We have also learnt about the different options available to concatenate multiple MySQL rows into one field. You can use any of them as per your requirement. group_concat() function is very useful as it provides many options such as delimiters, ordering, and unique values.<\/p>\n\n\n\n<p>Also read:<\/p>\n\n\n\n<p><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-see-foreign-keys-related-to-table-or-column\/\">How to See Foreign Keys Related to Table in MySQL<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-reset-auto-increment-in-mysql\/\">How to Reset Auto Increment in MySQL<\/a><br><a href=\"https:\/\/ubiq.co\/tech-blog\/how-to-list-users-in-mysql\/\">How to List Database Users in MySQL<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Often database programmers need to concatenate multiple MySQL rows into one field. Here is how to do this using group_concat() function.<\/p>\n","protected":false},"author":1,"featured_media":5629,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[324],"tags":[338],"class_list":["post-5610","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-mysql","tag-group-concat"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to Concatenate Multiple MySQL Rows into One Field - Ubiq BI<\/title>\n<meta name=\"description\" content=\"Often database programmers need to concatenate multiple MySQL rows into one field. Here is how to do this using group_concat() function.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Concatenate Multiple MySQL Rows into One Field - Ubiq BI\" \/>\n<meta property=\"og:description\" content=\"Often database programmers need to concatenate multiple MySQL rows into one field. Here is how to do this using group_concat() function.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/\" \/>\n<meta property=\"og:site_name\" content=\"Ubiq BI\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ubiqbi\" \/>\n<meta property=\"article:published_time\" content=\"2024-11-28T07:30:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-11-28T08:49:24+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/concatenate-multiple-mysql-rows-into-one-field.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"308\" \/>\n\t<meta property=\"og:image:height\" content=\"204\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Sreeram Sreenivasan\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:site\" content=\"@UbiqBI\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Sreeram Sreenivasan\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/\"},\"author\":{\"name\":\"Sreeram Sreenivasan\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"headline\":\"How to Concatenate Multiple MySQL Rows into One Field\",\"datePublished\":\"2024-11-28T07:30:47+00:00\",\"dateModified\":\"2024-11-28T08:49:24+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/\"},\"wordCount\":820,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/concatenate-multiple-mysql-rows-into-one-field.jpg?fit=308%2C204&ssl=1\",\"keywords\":[\"group concat\"],\"articleSection\":[\"MySQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/\",\"name\":\"How to Concatenate Multiple MySQL Rows into One Field - Ubiq BI\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/concatenate-multiple-mysql-rows-into-one-field.jpg?fit=308%2C204&ssl=1\",\"datePublished\":\"2024-11-28T07:30:47+00:00\",\"dateModified\":\"2024-11-28T08:49:24+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\"},\"description\":\"Often database programmers need to concatenate multiple MySQL rows into one field. Here is how to do this using group_concat() function.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/#primaryimage\",\"url\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/concatenate-multiple-mysql-rows-into-one-field.jpg?fit=308%2C204&ssl=1\",\"contentUrl\":\"https:\\\/\\\/i0.wp.com\\\/ubiq.co\\\/tech-blog\\\/wp-content\\\/uploads\\\/2024\\\/11\\\/concatenate-multiple-mysql-rows-into-one-field.jpg?fit=308%2C204&ssl=1\",\"width\":308,\"height\":204,\"caption\":\"concatenate multiple mysql rows into one field\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/how-to-concatenate-multiple-mysql-rows-into-one-field\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Concatenate Multiple MySQL Rows into One Field\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#website\",\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/\",\"name\":\"Ubiq BI\",\"description\":\"Build dashboards &amp; reports in minutes\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/#\\\/schema\\\/person\\\/db98d49a766a3a111d8510935ab90abc\",\"name\":\"Sreeram Sreenivasan\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g\",\"caption\":\"Sreeram Sreenivasan\"},\"description\":\"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.\",\"sameAs\":[\"https:\\\/\\\/www.linkedin.com\\\/in\\\/sreeram-sreenivasan\\\/\"],\"url\":\"https:\\\/\\\/ubiq.co\\\/tech-blog\\\/author\\\/wordpress\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Concatenate Multiple MySQL Rows into One Field - Ubiq BI","description":"Often database programmers need to concatenate multiple MySQL rows into one field. Here is how to do this using group_concat() function.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/","og_locale":"en_US","og_type":"article","og_title":"How to Concatenate Multiple MySQL Rows into One Field - Ubiq BI","og_description":"Often database programmers need to concatenate multiple MySQL rows into one field. Here is how to do this using group_concat() function.","og_url":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/","og_site_name":"Ubiq BI","article_publisher":"https:\/\/www.facebook.com\/ubiqbi","article_published_time":"2024-11-28T07:30:47+00:00","article_modified_time":"2024-11-28T08:49:24+00:00","og_image":[{"width":308,"height":204,"url":"https:\/\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/concatenate-multiple-mysql-rows-into-one-field.jpg","type":"image\/jpeg"}],"author":"Sreeram Sreenivasan","twitter_card":"summary_large_image","twitter_creator":"@UbiqBI","twitter_site":"@UbiqBI","twitter_misc":{"Written by":"Sreeram Sreenivasan","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#article","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/"},"author":{"name":"Sreeram Sreenivasan","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"headline":"How to Concatenate Multiple MySQL Rows into One Field","datePublished":"2024-11-28T07:30:47+00:00","dateModified":"2024-11-28T08:49:24+00:00","mainEntityOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/"},"wordCount":820,"commentCount":0,"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/concatenate-multiple-mysql-rows-into-one-field.jpg?fit=308%2C204&ssl=1","keywords":["group concat"],"articleSection":["MySQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/","url":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/","name":"How to Concatenate Multiple MySQL Rows into One Field - Ubiq BI","isPartOf":{"@id":"https:\/\/ubiq.co\/tech-blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#primaryimage"},"image":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#primaryimage"},"thumbnailUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/concatenate-multiple-mysql-rows-into-one-field.jpg?fit=308%2C204&ssl=1","datePublished":"2024-11-28T07:30:47+00:00","dateModified":"2024-11-28T08:49:24+00:00","author":{"@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc"},"description":"Often database programmers need to concatenate multiple MySQL rows into one field. Here is how to do this using group_concat() function.","breadcrumb":{"@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#primaryimage","url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/concatenate-multiple-mysql-rows-into-one-field.jpg?fit=308%2C204&ssl=1","contentUrl":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/concatenate-multiple-mysql-rows-into-one-field.jpg?fit=308%2C204&ssl=1","width":308,"height":204,"caption":"concatenate multiple mysql rows into one field"},{"@type":"BreadcrumbList","@id":"https:\/\/ubiq.co\/tech-blog\/how-to-concatenate-multiple-mysql-rows-into-one-field\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/ubiq.co\/tech-blog\/"},{"@type":"ListItem","position":2,"name":"How to Concatenate Multiple MySQL Rows into One Field"}]},{"@type":"WebSite","@id":"https:\/\/ubiq.co\/tech-blog\/#website","url":"https:\/\/ubiq.co\/tech-blog\/","name":"Ubiq BI","description":"Build dashboards &amp; reports in minutes","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/ubiq.co\/tech-blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/ubiq.co\/tech-blog\/#\/schema\/person\/db98d49a766a3a111d8510935ab90abc","name":"Sreeram Sreenivasan","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/4b3127ed2d4bb8efb3fa0bbb52cf2efd4d0156c97fc05a503537c883e8279947?s=96&d=mm&r=g","caption":"Sreeram Sreenivasan"},"description":"Sreeram Sreenivasan is the Founder of Ubiq. He has helped many Fortune 500 companies in the areas of BI &amp; software development.","sameAs":["https:\/\/www.linkedin.com\/in\/sreeram-sreenivasan\/"],"url":"https:\/\/ubiq.co\/tech-blog\/author\/wordpress\/"}]}},"jetpack_featured_media_url":"https:\/\/i0.wp.com\/ubiq.co\/tech-blog\/wp-content\/uploads\/2024\/11\/concatenate-multiple-mysql-rows-into-one-field.jpg?fit=308%2C204&ssl=1","jetpack_shortlink":"https:\/\/wp.me\/pbGGTT-1su","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5610","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/comments?post=5610"}],"version-history":[{"count":22,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5610\/revisions"}],"predecessor-version":[{"id":5633,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/posts\/5610\/revisions\/5633"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media\/5629"}],"wp:attachment":[{"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/media?parent=5610"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/categories?post=5610"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ubiq.co\/tech-blog\/wp-json\/wp\/v2\/tags?post=5610"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}