Complete the code to update the salary of employees and return the updated rows.
UPDATE employees SET salary = salary * 1.1 WHERE department = 'Sales' [1] id, salary;
The RETURNING clause in PostgreSQL allows you to get the rows affected by the UPDATE statement. Here, it returns the id and salary of updated employees.
Complete the code to delete employees from the Marketing department and return their names.
DELETE FROM employees WHERE department = 'Marketing' [1] name;
In PostgreSQL, the RETURNING clause after DELETE returns the specified columns of the deleted rows. Here, it returns the name of deleted employees.
Fix the error in the code to insert a new employee and return their id and name.
INSERT INTO employees (name, department, salary) VALUES ('Alice', 'HR', 50000) [1] id, name;
The RETURNING clause after INSERT returns the specified columns of the newly inserted row(s). Here, it returns id and name of the new employee.
Fill both blanks to update the price of products and return their id and new price.
UPDATE products SET price = price [1] 1.2 WHERE category = 'Books' [2] id, price;
The price is increased by multiplying by 1.2 using the * operator. The RETURNING clause returns the id and updated price of the products.
Fill all three blanks to insert a new order and return its id, customer_id, and total.
INSERT INTO orders (customer_id, total) VALUES ([1], [2]) [3] id, customer_id, total;
The values 123 and 250.75 are inserted for customer_id and total. The RETURNING clause returns the id, customer_id, and total of the new order.