</>
Skip to content
MySQL lessons (17/48)

MySQL — Update

Basic UPDATE

UPDATE users SET name = 'Jane' WHERE id = 1;

Update Multiple Columns

UPDATE users
SET name = 'Jane', email = 'jane@example.com'
WHERE id = 1;

Update All Rows

UPDATE users SET is_active = TRUE;

UPDATE Examples

-- Update single row
UPDATE products
SET price = 799.99
WHERE id = 1;

-- Update multiple rows
UPDATE products
SET stock = stock - 1
WHERE category = 'Electronics';

-- Update with condition
UPDATE users
SET is_active = FALSE
WHERE last_login < '2023-01-01';

-- Update using other columns
UPDATE products
SET price = price * 1.10
WHERE category = 'Premium';

UPDATE with LIMIT

-- Update first 5 rows
UPDATE users
SET is_active = FALSE
WHERE last_login < '2023-01-01'
LIMIT 5;

WARNING

-- Always use WHERE clause!
UPDATE users SET is_active = FALSE; -- Updates ALL rows!

-- Test with SELECT first
SELECT * FROM users WHERE condition;

Mini Practice

Write MySQL code that:

  1. Updates a single row
  2. Updates multiple columns
  3. Updates with conditions
  4. Tests with SELECT before update

Up Next

Next: Learn about Deleting Data.

Related Topics

Frequently Asked Questions about Update

What is Update in MySQL?

Update is a fundamental concept in MySQL. This lesson explains it step by step with clear examples, making it easy for beginners to understand.

How do I learn Update?

Start by reading the explanation above, then try the code examples. Practice by modifying the examples and experimenting with different values. Hands-on practice is the best way to learn Update.

Why is Update important in MySQL?

Update is essential for MySQL development. Understanding this concept will help you write better code and solve real-world problems more effectively.