String Aggregation Functions: Concept
Module: Aggregate Functions & Grouping
String aggregation functions concatenate multiple string values from grouped rows into a single delimited string, useful for creating lists and collections.
**Core Functions:**
PostgreSQL: STRING_AGG(column, delimiter)
MySQL: GROUP_CONCAT(column SEPARATOR delimiter)
SQL Server: STRING_AGG(column, delimiter)
**Basic Pattern:**
SELECT
category,
STRING_AGG(product_name, ', ') AS products
FROM products
GROUP BY category;
Result: "Laptop, Mouse, Keyboard" for Electronics category
**Ordering:**
STRING_AGG(column, delimiter ORDER BY sort_column)
**NULL Handling:**
- NULL values typically ignored
- Use COALESCE to replace NULL with default
Common in reporting and API responses. Used by backend engineers and data analysts to denormalize data for display and export.
Creates comma-separated lists, tag collections, and concatenated values. Essential for displaying multiple related items in single row: product tags, employee skills, order items.