既存のクエリは、連結された列を生成するために必要なすべてを返します。既存のクエリをサブクエリでラップする場合は、GROUP_CONCAT()
列と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;