JOIN and GROUP_CONCAT with three tables

后端 未结 2 1767
感情败类
感情败类 2020-12-14 22:17

I have three tables:

users:        sports:           user_sports:

id | name     id | name         id_user | id_sport | pref
---+--------  ---+------------           


        
2条回答
  •  感动是毒
    2020-12-14 22:57

    I think this is just a simple join and aggregation:

    select u.id, u.name, group_concat(s.name order by pref separator ',')
    from user_sports us join
         users u
         on us.id_user = u.id join
         sports s
         on us.id_sport = s.id
    group by u.id, u.name
    

提交回复
热议问题