SQL WHERE
The WHERE clause in SQL is used to filter records from a table. It specifies a condition, and only the rows that satisfy that condition are returned or affected.
Basic Syntax
SELECT column1, column2 FROM table_name WHERE condition;
WHERE with SELECT: Retrieve students from Delhi.
SELECT * FROM students WHERE city = 'Delhi';
WHERE with Comparison Operators
SELECT * FROM students WHERE marks > 80; Returns students who scored more than 80
WHERE with AND / OR
AND (both conditions must be true) SELECT * FROM students WHERE city = 'Delhi' AND marks > 80; OR (any condition true) SELECT * FROM students WHERE city = 'Delhi' OR city = 'Pune';
WHERE with BETWEEN: Used for a range.
SELECT * FROM students WHERE marks BETWEEN 70 AND 90;
WHERE with IN: Check multiple values.
SELECT *
FROM students
WHERE city IN ('Delhi', 'Mumbai');
WHERE with LIKE: Used for pattern matching.
SELECT * FROM students WHERE name LIKE 'R%'; Meaning: names starting with R.
Update
UPDATE students SET marks = 95 WHERE id = 1;
Summary
• WHERE filters rows based on conditions.
• Used with commands like SELECT, UPDATE, DELETE.