Uw bestaande query retourneert alles wat u nodig hebt om de aaneengeschakelde kolommen te produceren. Als u uw bestaande zoekopdracht in een subquery plaatst, kunt u GROUP_CONCAT()
beide kolommen en GROUP BY attribute_name
:
SELECT
attribute_name,
GROUP_CONCAT(attribute_value_id) AS attribute_value_ids,
GROUP_CONCAT(attribute_value) AS attribute_values
FROM (
/* Wrap the body of your existing query in a subselect */
SELECT
a.name AS attribute_name,
av.attribute_value_id,
av.value AS attribute_value
FROM
attribute_value av
INNER JOIN attribute a
ON av.attribute_id = a.attribute_id
WHERE
av.attribute_value_id IN
(SELECT attribute_value_id
FROM property_attribute
WHERE property_id = 1)
) attr_groups
GROUP BY attribute_name
ORDER BY attribute_name;