PostgreSQL - Aggregate Functions and GROUP BYWhich of the following is the correct syntax to aggregate names separated by commas using STRING_AGG in PostgreSQL?ASELECT STRING_AGG(name, ',') FROM users ORDER BY name;BSELECT STRING_AGG(name) FROM users;CSELECT STRING_AGG(name, ',') ORDER BY name FROM users;DSELECT STRING_AGG(name, ',') FROM users;Check Answer
Step-by-Step SolutionSolution:Step 1: Check basic STRING_AGG syntaxSTRING_AGG requires two arguments: the column and the separator, e.g., STRING_AGG(name, ',').Step 2: Validate query structureORDER BY inside STRING_AGG needs to be inside parentheses, not outside. SELECT STRING_AGG(name, ',') FROM users; is correct syntax without ordering.Final Answer:SELECT STRING_AGG(name, ',') FROM users; -> Option DQuick Check:Correct STRING_AGG syntax = SELECT STRING_AGG(name, ',') FROM users; [OK]Quick Trick: STRING_AGG needs column and separator inside parentheses [OK]Common Mistakes:Omitting separator argumentPlacing ORDER BY outside STRING_AGGUsing STRING_AGG without parentheses
Master "Aggregate Functions and GROUP BY" in PostgreSQL9 interactive learning modes - each teaches the same concept differentlyLearnWhyDeepVisualTryChallengeProjectRecallTime
More PostgreSQL Quizzes Aggregate Functions and GROUP BY - ROLLUP and CUBE for hierarchical totals - Quiz 14medium Aggregate Functions and GROUP BY - FILTER clause for conditional aggregation - Quiz 2easy JSON and JSONB - JSONB containment (@>) operator - Quiz 9hard Joins in PostgreSQL - INNER JOIN execution - Quiz 7medium Joins in PostgreSQL - NATURAL join and its risks - Quiz 14medium Subqueries in PostgreSQL - Subqueries in WHERE with IN - Quiz 14medium Subqueries in PostgreSQL - Subqueries in FROM (derived tables) - Quiz 3easy Subqueries in PostgreSQL - Why subqueries are needed - Quiz 4medium Subqueries in PostgreSQL - Scalar subqueries - Quiz 8hard Window Functions in PostgreSQL - FIRST_VALUE and LAST_VALUE - Quiz 8hard