Introduction
We use UPDATE to change data in a table. Updating multiple columns lets us change several pieces of information in one go.
UPDATE table_name SET column1 = value1, column2 = value2, ... WHERE condition;
UPDATE employees SET first_name = 'Anna', last_name = 'Smith' WHERE employee_id = 5;
UPDATE products SET price = 19.99, stock = 50 WHERE product_id = 10;
UPDATE orders SET status = 'Shipped', shipped_date = '2024-06-01' WHERE order_id = 100;
CREATE TABLE users ( id INT PRIMARY KEY, name VARCHAR(50), email VARCHAR(50), city VARCHAR(50) ); INSERT INTO users (id, name, email, city) VALUES (1, 'John Doe', 'john@example.com', 'New York'), (2, 'Jane Roe', 'jane@example.com', 'Los Angeles'); UPDATE users SET email = 'john.doe@example.com', city = 'Boston' WHERE id = 1; SELECT * FROM users WHERE id = 1;
UPDATE statement do when you specify multiple columns in the SET clause?price and stock, in a table named products?employees with columns salary and bonus, what will be the result of this query?UPDATE employees SET salary = salary + 1000, bonus = 500 WHERE department = 'Sales';
UPDATE orders SET status = 'Shipped' stock = 0 WHERE order_id = 123;
price and discount columns in the products table only for items where category is 'Electronics' and current stock is less than 10. Which query correctly does this?Pass the test and this pattern moves unknown