SQL Practice Logo

SQLPractice Online

String Aggregation Functions: Interview

Module: Aggregate Functions & Grouping

What is string aggregation and when would you use it?

String aggregation concatenates multiple string values from grouped rows into single delimited string. Used for creating comma-separated lists, tag collections, and denormalizing related data for display.

What are the syntax differences between PostgreSQL and MySQL?

PostgreSQL uses STRING_AGG(column, delimiter ORDER BY col). MySQL uses GROUP_CONCAT(column ORDER BY col SEPARATOR delimiter). Both achieve same result with different syntax.

Create comma-separated list of product names per category, ordered alphabetically

SELECT category, STRING_AGG(product_name, ', ' ORDER BY product_name) AS products FROM products GROUP BY category;

STRING_AGG with ORDER BY creates alphabetically sorted comma-separated list per category.