Akhil
Akhil

Reputation: 97

Merge Multiple Rows in One Row Mysql

I have a sql table having multiple rows in which i want to get single row from same column value in my case SKU Column.I want to merge multiple rows from same sku value into one row having all values of attribute_id and attribute_value.

enter image description here

Upvotes: 3

Views: 1109

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 520908

If you are OK with having a comma-separated list of attribute IDs and values per each sku, then you could use GROUP_CONCAT:

SELECT sku,
       GROUP_CONCAT(attribute_id)    AS attribute_id,
       GROUP_CONCAT(attribute_value) AS attribute_value
FROM yourTable
GROUP BY sku

Upvotes: 5

Related Questions