AND OR — SQL Technical Interview Questions & Answers
AND OR
AND OR
- Mix AND and OR only with parentheses. WHERE (city = 'Pune' OR city = 'Goa') AND marks < 40; fail students from those cities.
- Without brackets MySQL does AND first. Your English sentence is not the operator order.
- Trap: writing AND/OR chains from spoken language without drawing two groups on paper.
- On the example next to this theory: AND OR — wHERE combines predicates with AND/OR; LIKE does pattern match.
Technical Interview Tip: (city = 'Pune' OR city = 'Goa') AND marks < 40
Code Examples for AND OR
AND OR — sample query
CREATE TABLE products (id INTEGER PRIMARY KEY, name TEXT, price REAL);
INSERT INTO products VALUES (1, 'Pen', 10), (2, 'Book', 200), (3, 'Bag', 50);
SELECT * FROM products
WHERE price BETWEEN 20 AND 150 AND name LIKE 'B%';AND OR — wHERE combines predicates with AND/OR; LIKE does pattern match.
How to Explain AND OR to an Interviewer
How do you mix AND and OR?
Parentheses around the OR group