Lesson 17 — Conditional UPDATE
UPDATE: change existing rows
UPDATE table SET column = value WHERE condition changes rows that match. The SET part can use the old value: SET price = price * 0.9 gives a 10% discount. After an UPDATE, cursor.rowcount tells you how many rows changed.
UPDATE staff SET salary = salary * 1.05 WHERE team = 'support'
Watch out: an UPDATE without WHERE changes every row in the table. Always write the WHERE first.
Why it matters: price changes, status updates and "mark as read" are all UPDATEs — and a missing WHERE is a classic production accident.
Write the UPDATE giving a 10% discount (price * 0.9) only to books. Expected: 2 rows changed.
Run your code — when the output matches the task, you will see a green check. Then mark the lesson complete.
A quick 3-question quiz on this lesson — instant feedback.
Ready for more? Optional paid resources that pick up where this lesson leaves off.
Some links on this page are affiliate links: we may earn a commission at no extra cost to you. As an Amazon Associate I earn from qualifying purchases.
Project-based Databases & SQL courses if you want a structured paid path after the free lessons. Wait for a sale — prices drop often.
Browse on Udemy →Search Amazon for Databases & SQL books — check the publication year so the examples match current versions.
Search Amazon →