Part 59: String Aggregation: STRING_AGG & GROUP_CONCAT
Aggregate functions can also concatenate text strings across rows.
1. PostgreSQL: STRING_AGG()
SELECT
post_id,
STRING_AGG(tag_name, ', ' ORDER BY tag_name) AS tags
FROM post_tags
GROUP BY post_id;
2. MySQL: GROUP_CONCAT()
SELECT
post_id,
GROUP_CONCAT(tag_name ORDER BY tag_name SEPARATOR ', ') AS tags
FROM post_tags
GROUP BY post_id;
Key Takeaways
- Concatenate multiple child records into a comma-delimited string without N+1 queries.
In Part 60, we conclude Module 6 with a Real-World Sales Analytics Dashboard Query Project!

