Include null results in group_concat

前端 未结 2 1728
旧时难觅i
旧时难觅i 2021-01-23 04:26

I have two tables like this

profile_answers

+---------+------------+
|      id | class_name |
+---------+------------+
|       1 | Class         


        
相关标签:
2条回答
  • 2021-01-23 04:48
    SELECT id,IFNULL(samples,'NULL') sample FROM 
    (
        SELECT
            AA.id,
            GROUP_CONCAT(DISTINCT BB.sample) samples
        FROM
            profile_answers AA LEFT JOIN educations BB
            ON AA.id = BB.profile_answers_id
        GROUP BY AA.id
    ) A;
    
    0 讨论(0)
  • 2021-01-23 05:14

    Looks like you're missing your GROUP BY:

    select profile_answers.id, GROUP_CONCAT(educations.sample) 
    from profile_answers
    LEFT JOIN educations ON educations.profile_answers_id = profile_answers.id
    GROUP BY profile_answers.id
    

    I also altered your JOIN to make the profile_answers table your main table.

    Good luck.

    0 讨论(0)
提交回复
热议问题