Recall & Review
beginner
What does the SQL UPDATE statement do?
The UPDATE statement changes existing data in a table by modifying one or more columns for rows that meet a condition.
Click to reveal answer
beginner
What is a subquery in SQL?
A subquery is a query nested inside another query. It runs first and its result is used by the outer query.
Click to reveal answer
intermediate
How can a subquery be used in an UPDATE statement?
A subquery can provide values to update columns or specify which rows to update based on data from another table.
Click to reveal answer
intermediate
Example: What does this SQL do?
UPDATE employees SET salary = (SELECT AVG(salary) FROM employees) WHERE department = 'Sales';
It sets the salary of all employees in the Sales department to the average salary of all employees.
Click to reveal answer
beginner
Why previewing a subquery before running an UPDATE is helpful?
Previewing lets you see the data the subquery returns, so you can avoid mistakes and update only the intended rows with correct values.
Click to reveal answer
What does the subquery in an UPDATE statement do?
✗ Incorrect
The subquery provides values or conditions used to update rows in the main table.
Which SQL keyword is used to change data in existing rows?
✗ Incorrect
UPDATE modifies existing rows in a table.
What will this query do?
UPDATE products SET price = price * 1.1 WHERE category = 'Books';
✗ Incorrect
It increases the price by 10% for products in the Books category.
Why should you run a subquery alone before using it in UPDATE?
✗ Incorrect
Running the subquery alone helps verify it returns the correct data for the update.
Which clause specifies which rows to update in an UPDATE statement?
✗ Incorrect
The WHERE clause filters rows to update.
Explain how to use a subquery inside an UPDATE statement and why it is useful.
Think about how you can get data from one place to update another.
You got /4 concepts.
Describe the steps you take before running an UPDATE with a subquery to ensure it works correctly.
Preview and verify before changing data.
You got /4 concepts.