Get the App
SLTechnology News&Howtos  ›  Database  › 

Sql splicing multiple information in the same field

Shulou Source: shulou.com Published: 2022-06-01 13:43:44 10月03日 Update

Write down what you inadvertently use today.

such as

T_Stu_Hobby student interest table. Associate the student table and the interest table. Many-to-many relationship

Stu_ID Hobby_ID

=

1 1

1 2

1 3

2 1

2 2

How to get such a result:

Stu_ID Hobby_ID

1 '1jue 2jin3'

2 '1par 2'

More 0

Now there is a user table, a role table, and a table that connects users and roles. I query the information of users, but this user has multiple roles, multiple tables query, and the same user has multiple roles. Concatenate the results of these role fields in the role field.

Select group_concat (the fields you want to merge) what is the grouping of the from table group by

Can be realized.

Tags: Roles users fields multiple interests students results queries information student interests inadvertently more user tables associations grouping Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno vpn Huawei MySQL Linux Xiaomi