Merge the multi-row records obtained by querying the name field, which can be implemented through a program, but can also be completed directly at the SQL layer. For more information, see the following two tables a, B, table B is associated with table a through the field id, and table a and Table B are one-to-many relationships. Assume that Table B has a field name. now you need to query the records in Table a and obtain the name information stored in Table B according to the regular query, the number of rows to be displayed. if you want to display only the number of rows in table a, you need to merge the multiple rows in the query name field. this can be achieved through a program, but it can also be completed directly at the SQL layer.
Method:
Using the group_concat () method, the parameter is the field to be merged. the default delimiter of the merged field is comma, which can be specified by the separator parameter. this method is often used together with group.
Example:
Select a. *, group_concat (B. name separator '-') as name from a left join B on a. id = B. id group by a. id;