Using GROUP_CONCAT on subquery in MySQL

前端 未结 5 1706
我在风中等你
我在风中等你 2021-02-02 06:28

I have a MySQL query in which I want to include a list of ID\'s from another table. On the website, people are able to add certain items, and people can then add those items to

5条回答
  •  余生分开走
    2021-02-02 06:47

    You can't access variables in the outer scope in such queries (can't use items.id there). You should rather try something like

    SELECT
        items.name,
        items.color,
        CONCAT(favourites.userid) as idlist
    FROM
        items
    INNER JOIN favourites ON items.id = favourites.itemid
    WHERE
        items.id = $someid
    GROUP BY
        items.name,
        items.color;
    

    Expand the list of fields as needed (name, color...).

提交回复
热议问题