Query using group_concat is returning only one row

前端 未结 3 853
旧巷少年郎
旧巷少年郎 2020-12-06 05:26

This is a query that is supposed to get the user\'s information, their project\'s information, and a group_concat of all the image paths that such project is associated to.

3条回答
  •  天命终不由人
    2020-12-06 06:05

    When I try to use group_concat it just returns me one row and I do not understand why.

    Because you have not used the GROUP BY clause in your query. When using aggregate functions like GROUP_CONCAT you need to tell the database about the column using which you want your data to be combined.

    Currently your query is grouping all records and giving 1 record in the output.

    If you add GROUP BY users.userid in the query then the records will be grouped by unique userid's. I updated your fiddle and it now gives 2 records: http://www.sqlfiddle.com/#!2/867f6/18

    Please note: In standard SQL queries, columns listed in the GROUP BY clause should match the column in the SELECT clause (except the aggregate functions).

提交回复
热议问题