Bird
0
0

Given the table employees(id INT, salary INT) with rows:

medium📝 query result Q4 of 15
PostgreSQL - Set Operations and Advanced Queries
Given the table employees(id INT, salary INT) with rows:
(1, 5000), (2, 6000), (3, 7000)
What will be the output of:
UPDATE employees SET salary = salary + 500 WHERE id <= 2 RETURNING id, salary;
A(1, 5500), (2, 6500), (3, 7000)
BNo rows returned
C(3, 7000)
D(1, 5500), (2, 6500)
Step-by-Step Solution
Solution:
  1. Step 1: Identify rows matching WHERE condition

    Rows with id 1 and 2 satisfy id <= 2.
  2. Step 2: Calculate updated salaries and returned rows

    Salary for id 1 becomes 5000 + 500 = 5500, for id 2 becomes 6000 + 500 = 6500. Only these rows are returned.
  3. Final Answer:

    (1, 5500), (2, 6500) -> Option D
  4. Quick Check:

    RETURNING outputs updated rows only [OK]
Quick Trick: RETURNING shows only rows matching WHERE and updated [OK]
Common Mistakes:
  • Expecting all rows returned
  • Ignoring WHERE clause
  • Assuming unchanged rows are returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More PostgreSQL Quizzes