Din eksisterende forespørgsel returnerer alt, hvad du behøver for at producere de sammenkædede kolonner. Hvis du ombryder din eksisterende forespørgsel i en underforespørgsel, kan du GROUP_CONCAT()
både kolonner og 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;