Introduction
The UPDATE statement changes existing data in a table. The WHERE clause limits which rows get changed.
The UPDATE statement changes existing data in a table. The WHERE clause limits which rows get changed.
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
UPDATE employees SET salary = 5000 WHERE employee_id = 101;
UPDATE products SET price = price * 1.1 WHERE category = 'Books';
UPDATE orders SET status = 'shipped', shipped_date = '2024-06-01' WHERE order_id = 2001;
This example creates a customers table, inserts three rows, then updates Bob's city to San Francisco. Finally, it shows all customers.
CREATE TABLE customers ( id INT PRIMARY KEY, name VARCHAR(50), city VARCHAR(50) ); INSERT INTO customers (id, name, city) VALUES (1, 'Alice', 'New York'), (2, 'Bob', 'Los Angeles'), (3, 'Charlie', 'Chicago'); UPDATE customers SET city = 'San Francisco' WHERE name = 'Bob'; SELECT * FROM customers ORDER BY id;
Always double-check your WHERE clause to avoid updating unintended rows.
If you omit the WHERE clause, all rows in the table will be updated.
You can use multiple conditions in WHERE with AND/OR to be more specific.
UPDATE changes data in existing rows.
WHERE clause controls which rows get updated.
Be careful: no WHERE means update all rows.
WHERE clause do in an UPDATE statement in MySQL?UPDATE command changes data in existing rows of a table.WHERE clause limits which rows get changed. Without it, all rows update.salary to 5000 for employees with id 10 in MySQL?products with columns id, name, and price, what will be the price of product with id = 3 after running this query?UPDATE products SET price = price + 10 WHERE id = 3;
id = 3 was 50.id = 3.UPDATE users SET age = 30 WHERE;
orders with columns order_id, status, and amount. You want to increase the amount by 20% only for orders with status 'pending' and amount less than 100. Which query correctly does this?status is 'pending' AND amount is less than 100.amount by 1.2.Pass the test and this pattern moves unknown