UPDATE products SET price = price + 2 WHERE price < 10;
medium
A. All products will have their price increased by 2.
B. Only products with price less than 10 will have their price increased by 2.
C. No products will be updated because price is not changed.
D. Syntax error due to missing WHERE clause.
Solution
Step 1: Identify rows matching WHERE condition
Prices less than 10 are 5 and 3 (Pencil and Eraser).
Step 2: Apply UPDATE only to matching rows
Only Pencil and Eraser prices increase by 2, Pen remains 10.
Final Answer:
Only products with price less than 10 will have their price increased by 2. -> Option B
Quick Check:
WHERE filters rows updated [OK]
Hint: WHERE limits which rows get updated, others stay same [OK]
Common Mistakes:
Assuming all rows update without WHERE
Thinking price must be reset, not incremented
Confusing syntax error with correct query
4.
Find the error in this query:
UPDATE employees SET salary = 6000 WHERE;
medium
A. Missing condition after WHERE clause.
B. Missing SET keyword.
C. Incorrect table name.
D. No error, query is correct.
Solution
Step 1: Analyze the WHERE clause
The WHERE clause is incomplete; it must have a condition after it.
Step 2: Check other parts of query
SET keyword and table name are correct; only WHERE is incomplete.
Final Answer:
Missing condition after WHERE clause. -> Option A
Quick Check:
WHERE needs a condition [OK]
Hint: WHERE must always have a condition after it [OK]
Common Mistakes:
Leaving WHERE empty
Confusing missing SET with WHERE error
Assuming query runs without WHERE condition
5.
You have a table students with columns id, name, and grade. You want to increase the grade by 5 for all students who scored less than 50, but not exceed 50 after update. Which query correctly does this?
hard
A. UPDATE students SET grade = CASE WHEN grade + 5 > 50 THEN 50 ELSE grade + 5 END WHERE grade < 50;
B. UPDATE students SET grade = grade + 5 WHERE grade < 50 AND grade + 5 <= 50;
C. UPDATE students SET grade = grade + 5 WHERE grade < 50;
D. UPDATE students SET grade = 50 WHERE grade < 50;
Solution
Step 1: Understand the requirement
Increase grade by 5 only for grades less than 50, but cap max grade at 50.
Step 2: Analyze each option
UPDATE students SET grade = 50 WHERE grade < 50; sets all below 50 to 50 directly, no increase by 5. UPDATE students SET grade = grade + 5 WHERE grade < 50 AND grade + 5 <= 50; increases by 5 only if result ≤ 50, skipping some rows. UPDATE students SET grade = grade + 5 WHERE grade < 50; increases by 5 without capping at 50. UPDATE students SET grade = CASE WHEN grade + 5 > 50 THEN 50 ELSE grade + 5 END WHERE grade < 50; uses CASE to increase by 5 but caps at 50 correctly.
Final Answer:
UPDATE students SET grade = CASE WHEN grade + 5 > 50 THEN 50 ELSE grade + 5 END WHERE grade < 50; -> Option A
Quick Check:
Use CASE to cap values in UPDATE [OK]
Hint: Use CASE in UPDATE to handle conditional value changes [OK]
Common Mistakes:
Not capping grade at 50
Updating all rows without WHERE
Skipping rows that would exceed 50
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.