Introduction
We use DELETE with WHERE to remove only specific rows from a table, not everything. This helps keep the data we want and remove the rest.
DELETE FROM table_name WHERE condition;
DELETE FROM employees WHERE employee_id = 5;
DELETE FROM orders WHERE order_date < '2023-01-01';
DELETE FROM users WHERE status = 'inactive';
CREATE TABLE products (id INT, name VARCHAR(20), price INT); INSERT INTO products VALUES (1, 'Pen', 10), (2, 'Book', 50), (3, 'Pencil', 5); DELETE FROM products WHERE price < 10; SELECT * FROM products;
DELETE statement with a WHERE condition do in SQL?age is greater than 30 from a table named employees?products with rows:{id:1, name:'Pen', stock:10}, {id:2, name:'Pencil', stock:0}, {id:3, name:'Eraser', stock:5}DELETE FROM products WHERE stock = 0;
DELETE FROM orders WHERE;
users with columns id, name, and status. You want to delete all users whose status is either 'inactive' or 'banned'. Which query correctly deletes these users?DELETE FROM users WHERE status = 'inactive' OR 'banned'; -- OR 'banned' (literal string) evaluates to true, deleting all rows.DELETE FROM users WHERE status IN ('inactive', 'banned'); -- correctly matches either value.DELETE FROM users WHERE status = 'inactive' AND status = 'banned'; -- AND condition is impossible, deletes none.DELETE FROM users WHERE status = 'inactive', 'banned'; -- invalid comma syntax.Pass the test and this pattern moves unknown