Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

What is the scene of group_concat usage?

Shulou Source: shulou.com Published: 2022-06-02 00:41:04 10月01日 Update

In this issue, Xiaobian will bring you about the use of group_concat scenarios. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.

usage scenarios

When two tables are inner join, and the records in the two tables are in a one-to-many relationship, it is necessary to merge the records of multiple tables into one row, for example, the relationship between examination and examination label, and obtain the examination information and all label information corresponding to each examination through one query. All labels are merged into one field, separated by commas. Grammar:

GROUP_CONCAT([DISTINCT] expr [,expr ...]

[ORDER BY {unsigned_integer | col_name | expr}

[ASC | DESC] [,col_name ...]]

[SEPARATOR str_val])

For example:

SELECT t.id as exam_id ,t.name``

, GROUP_CONCAT(t2.label_id order by t2.label_id SEPARATOR ',') as label_ids

from center_exam.examination t ,center_exam.exam_label t2

where t.id = t2.biz_id

and t2.type = 'examination'

AND t.tenant_id = 1

GROUP BY t.id

**sample picture **

The above is what the group_concat use scenario shared by Xiaobian is like. If there is a similar doubt, please refer to the above analysis for understanding. If you want to know more about it, please pay attention to the industry information channel.

Tags: Exams scenes tags information content composition analysis line major small and medium examples rich content pictures fields that is articles more knowledge articles industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Docker Microsoft NVidia OPPO Reno