mysql - add additional data to duplicate records -
i have code checks how many duplicate codes there are:
mysql> select code, count(code) dup tg_user group code having dup>1 order dup;   this returns:
+------------+-----+ | ccc002     |   5 | | bar003     |   6 | | fir001     |   6 | | njs001     |   6 | | del004     |   6 | | bra009     |   7 | | tsh011     |  11 | | sho005     |  19 | +------------+-----+ 432 rows in set (0.08 sec)   the table structure is:
mysql> describe tg_user; +---------------+--------------+------+-----+---------+----------------+ | field         | type         | null | key | default |          | +---------------+--------------+------+-----+---------+----------------+ | user_id       | int(11)      | no   | pri | null    | auto_increment | | user_name     | varchar(30)  | yes  | uni | null    |                | | email_address | varchar(255) | yes  | uni | null    |                | | code          | varchar(25)  | yes  |     | null    |                | +---------------+--------------+------+-----+---------+----------------+ 32 rows in set (0.00 sec)   what correct way add email_address each duplicate record, comes list, like:
| sho005     |  19 | name@domai.tld, name@domai.tld...       | +------------+-----+-----------------------------------------+ 432 rows in set (0.08 sec)   any advice appreciated
group_concat joins values comma. add distinct filter out duplicates
select code, count(code) dup, group_concat(distinct email_address) tg_user group code having dup>1 order dup;      
Comments
Post a Comment