Bird
0
0

Consider this PostgreSQL query run on a server:

medium📝 query result Q13 of 15
PostgreSQL - PL/pgSQL Fundamentals
Consider this PostgreSQL query run on a server:
INSERT INTO users (id, name) VALUES (1, 'Alice');
INSERT INTO users (id, name) VALUES (2, 'Bob');
SELECT * FROM users ORDER BY id;

What will be the output of the SELECT query?
A[{"id":1, "name":"Alice"}, {"id":2, "name":"Bob"}]
B[{"name":"Alice"}, {"name":"Bob"}]
C[{1, 'Alice'}, {2, 'Bob'}]
DSyntax error
Step-by-Step Solution
Solution:
  1. Step 1: Understand the INSERT commands

    Two rows are inserted with ids 1 and 2 and names Alice and Bob.
  2. Step 2: Analyze the SELECT query

    The SELECT fetches all rows ordered by id, so rows appear in order 1 then 2.
  3. Final Answer:

    [{"id":1, "name":"Alice"}, {"id":2, "name":"Bob"}] -> Option A
  4. Quick Check:

    Inserted rows appear ordered by id [OK]
Quick Trick: SELECT * ORDER BY id returns rows sorted by id [OK]
Common Mistakes:
  • Ignoring ORDER BY and expecting random order
  • Expecting only names without ids
  • Thinking syntax error due to multiple inserts

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes