0
0
PostgreSQLquery~10 mins

UPDATE with RETURNING clause in PostgreSQL - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to update the salary of employees in the 'employees' table.

PostgreSQL
UPDATE employees SET salary = salary [1] 1000 WHERE department = 'Sales';
Drag options to blanks, or click blank then click option'
A+
B-
C*
D/
Attempts:
3 left
💡 Hint
Common Mistakes
Using '-' will decrease the salary instead of increasing it.
Using '*' or '/' will multiply or divide the salary, which is not intended here.
2fill in blank
medium

Complete the code to return the updated rows after increasing the salary.

PostgreSQL
UPDATE employees SET salary = salary + 500 WHERE id = 10 [1] salary, id;
Drag options to blanks, or click blank then click option'
ARETURNING
BRETURN
COUTPUT
DSELECT
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'RETURN' alone is not valid SQL syntax here.
Using 'OUTPUT' is a SQL Server syntax, not PostgreSQL.
Using 'SELECT' after UPDATE is incorrect.
3fill in blank
hard

Fix the error in the code to correctly update and return the employee's name and new salary.

PostgreSQL
UPDATE employees SET salary = salary + 200 WHERE id = 5 RETURNING [1];
Drag options to blanks, or click blank then click option'
Aname; salary
Bname salary
Cname, salary
Dname salary,
Attempts:
3 left
💡 Hint
Common Mistakes
Leaving out commas between column names.
Adding semicolons inside the RETURNING clause.
4fill in blank
hard

Fill both blanks to update the 'status' and return the 'id' and 'status' of updated rows.

PostgreSQL
UPDATE orders SET status = [1] WHERE shipped = false RETURNING [2], status;
Drag options to blanks, or click blank then click option'
A'shipped'
Bid
Corder_id
D'delivered'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using quotes around string values in the SET clause.
Returning a column that does not exist or is not relevant.
5fill in blank
hard

Fill all three blanks to update 'quantity', return 'order_id', 'quantity', and only rows where quantity is greater than 10.

PostgreSQL
UPDATE order_items SET quantity = quantity - [1] WHERE quantity > [2] RETURNING [3], quantity;
Drag options to blanks, or click blank then click option'
A5
B10
Corder_id
D1
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong numbers for subtraction or filtering.
Returning a column name that does not exist.