Bird
0
0

Which of the following is the correct syntax to use JSON_AGG in a query?

easy📝 Syntax Q12 of 15
PostgreSQL - Aggregate Functions and GROUP BY
Which of the following is the correct syntax to use JSON_AGG in a query?
ASELECT JSON_AGG(column_name) table_name;
BSELECT JSON_AGG FROM table_name WHERE column_name;
CSELECT JSON_AGG(column_name) WHERE table_name;
DSELECT JSON_AGG(column_name) FROM table_name;
Step-by-Step Solution
Solution:
  1. Step 1: Review correct SQL aggregate function syntax

    Aggregate functions like JSON_AGG require parentheses around the column and a FROM clause specifying the table.
  2. Step 2: Check each option for syntax correctness

    SELECT JSON_AGG(column_name) FROM table_name; uses correct syntax: SELECT JSON_AGG(column_name) FROM table_name; Others miss FROM or parentheses or have misplaced WHERE.
  3. Final Answer:

    SELECT JSON_AGG(column_name) FROM table_name; -> Option D
  4. Quick Check:

    Correct aggregate syntax = SELECT JSON_AGG(column_name) FROM table_name; [OK]
Quick Trick: Aggregate functions need parentheses and FROM clause [OK]
Common Mistakes:
  • Omitting FROM clause
  • Missing parentheses after JSON_AGG
  • Misplacing WHERE clause

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes