GROUP_CONCAT() function (AKA poor man's window function) returns a string result with the comma(,) concatenated non-NULL values from a group. It returns NULL if there are no non-NULL values.
You can use GROUP_CONCAT() to concatenate multiple MySQL rows into one field.
For the following table i88ca:
id | emailid | email_tagid |
509 | 227776 | 69 |
508 | 227776 | 74 |
511 | 227776 | 78 |
512 | 227776 | 81 |
510 | 227776 | 84 |
517 | 228767 | 69 |
516 | 228767 | 77 |
513 | 228767 | 79 |
514 | 228767 | 81 |
515 | 228767 | 84 |
select emailid, group_concat(email_tagid) from i88ca group by emailid;
returns:
emailid | group_concat(email_tagid) |
227776 | 69,74,78,81,84 |
228767 | 69,77,79,81,84 |
More options:
select emailid, group_concat(distinct email_tagid order by email_tagid asc separator ' ') from i88ca group by emailid;
returns:
emailid | group_concat(distinct email_tagid order by email_tagid asc separator ' ') |
227776 | 69 74 78 81 84 |
228767 | 69 77 79 81 84 |
Comments
Post a Comment