Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**STRING_AGG** (PostgreSQL): SELECT STRING_AGG(col, ', ' ORDER BY id) FROM (SELECT col FROM t LIMIT 3) sub. **LISTAGG** (Oracle), **GROUP_CONCAT** (MySQL), **ARRAY_AGG** (returns array). For exactly 3 rows: LIMIT 3 in subquery. **Determinism**: ORDER BY in agg....
STRING_AGG (PostgreSQL): SELECT STRING_AGG(col, ', ' ORDER BY id) FROM (SELECT col FROM t LIMIT 3) sub. LISTAGG (Oracle), GROUP_CONCAT (MySQL), ARRAY_AGG (returns array). For exactly 3 rows: LIMIT 3 in subquery. Determinism: ORDER BY in agg. Null handling: STRING_AGG ignores NULL by default.
Red Flag: No ORDER BY—non-deterministic result. Pro-Move: 'We used STRING_AGG with ORDER BY and COALESCE for nulls—consistent report output across runs.'
According to DataEngPrep.tech, this is one of the most frequently asked SQL interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.