Bird
0
0

Given the table fruits with rows: ('apple'), ('banana'), ('cherry'), what is the result of this query?

medium📝 query result Q13 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Given the table fruits with rows: ('apple'), ('banana'), ('cherry'), what is the result of this query?
SELECT STRING_AGG(name, '; ' ORDER BY name) FROM fruits;
A'apple; banana; cherry'
B'banana; apple; cherry'
C'cherry; banana; apple'
D'apple, banana, cherry'
Step-by-Step Solution
Solution:
  1. Step 1: Understand ORDER BY inside STRING_AGG

    The query orders names alphabetically: apple, banana, cherry.
  2. Step 2: Check separator and output

    Separator is '; ', so the result joins names with '; ' in order.
  3. Final Answer:

    'apple; banana; cherry' -> Option A
  4. Quick Check:

    Ordered join with '; ' separator = 'apple; banana; cherry' [OK]
Quick Trick: ORDER BY inside STRING_AGG sorts before joining [OK]
Common Mistakes:
  • Ignoring ORDER BY inside STRING_AGG
  • Using wrong separator
  • Assuming default comma separator

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes