BeginnerCoder

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.

Want it another way?
Task

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.

← Back
Next →
Test your knowledge

A quick 3-question quiz on this lesson — instant feedback.

Enjoying this lesson? Share it.

Keep going with Databases & SQL

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.