0
0
SQLquery~5 mins

UPDATE with subquery preview in SQL - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
AProvides values or conditions for the update
BDeletes rows from the table
CCreates a new table
DChanges the table structure
Which SQL keyword is used to change data in existing rows?
ASELECT
BINSERT
CUPDATE
DDELETE
What will this query do?
UPDATE products SET price = price * 1.1 WHERE category = 'Books';
AAdd new books with price 1.1
BDelete all books
CSet price to 1.1 for books
DIncrease price by 10% for all books
Why should you run a subquery alone before using it in UPDATE?
ATo create a new table
BTo check the data it returns
CTo delete data
DTo change table structure
Which clause specifies which rows to update in an UPDATE statement?
AWHERE
BFROM
CGROUP BY
DORDER BY
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.