GROUP_CONCAT([DISTINCT] column_name [ORDER BY column_name ASC|DESC] [SEPARATOR 'string'])
GROUP_CONCAT : 여러 행의 데이터를 그룹화하여 하나의 행에 문자열로 통합 가능DISCINCT : 중복된 값을 제거하고 연결column_name : 연결할 컬럼 이름 지정ORDER BY : 연결된 값 순서 지정SEPARATOR : 각 값 사이에 삽입할 구분자 지정, 기본값은 ,SELECT category_id, GROUP_CONCAT(product_name) AS product_list
FROM products
GROUP BY category_id;
| category_id | product_list |
|---|---|
| 1 | Chair,Table,Lamp |
| 2 | Laptop,Monitor,Keyboard |