OR — SQL Technical Interview Questions & Answers

OR

OR

  • OR means at least one condition true. WHERE city = 'Pune' OR city = 'Goa'; Same idea as city IN ('Pune','Goa') — IN is cleaner for a list.
  • AND is evaluated before OR if you skip brackets. WHERE city = 'Pune' OR city = 'Goa' AND marks < 40 is not ‘(Pune or Goa) and fail’. Write brackets every time.
  • Trap: OR with a NULL-safe thought missing. Trap: huge OR lists instead of IN or a lookup table.
  • On the example next to this theory: OR — wHERE combines predicates with AND/OR; LIKE does pattern match.

Technical Interview Tip: WHERE city IN ('Pune','Goa'); or OR with brackets.

Code Examples for OR

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%';

OR — wHERE combines predicates with AND/OR; LIKE does pattern match.

How to Explain OR to an Interviewer

Pune or Goa students?

WHERE city = 'Pune' OR city = 'Goa' or IN ('Pune','Goa')