Bird
0
0

Which of the following is the correct syntax to aggregate names separated by commas using STRING_AGG in PostgreSQL?

easy📝 Syntax Q12 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Which 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;
Step-by-Step Solution
Solution:
  1. Step 1: Check basic STRING_AGG syntax

    STRING_AGG requires two arguments: the column and the separator, e.g., STRING_AGG(name, ',').
  2. Step 2: Validate query structure

    ORDER BY inside STRING_AGG needs to be inside parentheses, not outside. SELECT STRING_AGG(name, ',') FROM users; is correct syntax without ordering.
  3. Final Answer:

    SELECT STRING_AGG(name, ',') FROM users; -> Option D
  4. Quick 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 argument
  • Placing ORDER BY outside STRING_AGG
  • Using STRING_AGG without parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes