Merge of same field values in database (mysql)

The first time I encountered two or more pieces of data in the database received in an input box, at first I thought of solving the problem with a collection, and finally it can be solved through SQL statements after consulting.

GROUP_CONCAT(`member_pic` SEPARATOR ',') memberPic, explained below:


Glossary:

     1.concat():  Concatenate multiple strings into one string.

     Note: Oracle's CONCAT() only allows two parameters; only two strings can be concatenated at a time, but in Oracle, we can use '||' to concatenate multiple strings at a time.

     2.group_concat():   group_concat( [distinct] field to be connected [order by sorting field asc/desc] [separator 'separator'] ), this function returns a string result, the result is combined by the value connection in the group become.

     Note: Duplicate values ​​can be excluded by using distinct; if you want to sort the values ​​in the result, you can use the order by clause;

     3.separator:  separator is a string value, the default is a comma.



Guess you like

Origin blog.csdn.net/jianshou6442/article/details/80774125