Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What is the scene of group_concat usage?

2025-04-08 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report