Multiple rows to one row query

后端 未结 3 1918
日久生厌
日久生厌 2020-12-29 17:43

On my database when i do this query:

SELECT *
FROM users u
LEFT JOIN usersToStrategy uts on uts.userID = u.userID
LEFT JOIN strategy s on uts.stratID  = s.st         


        
相关标签:
3条回答
  • 2020-12-29 17:55

    I think you are looking for GROUP_CONCAT

    SELECT userID, username, fName, GROUP_CONCAT(stratNames SEPARATOR ', ') AS strats
    FROM users u
    LEFT JOIN usersToStrategy uts on uts.userID = u.userID
    LEFT JOIN strategy s on uts.stratID  = s.stratID  
    GROUP BY userID, username, fName
    
    0 讨论(0)
  • 2020-12-29 18:06

    You use GROUP_CONCAT.

    0 讨论(0)
  • 2020-12-29 18:13

    Use GROUP_CONCAT like this

    SELECT userID,
    username,
    fName,   
    GROUP_CONCAT(stratNames)
    FROM users u
    LEFT JOIN usersToStrategy uts on uts.userID = u.userID 
    LEFT JOIN strategy s on uts.stratID  = s.stratID   
    GROUP BY username;
    
    0 讨论(0)
提交回复
热议问题