BETWEEN — SQL Technical Interview Questions & Answers

BETWEEN

BETWEEN

  • BETWEEN is inclusive on both ends. WHERE marks BETWEEN 40 AND 60 means marks >= 40 AND marks <= 60. Swap 60 AND 40 and you get empty — low first.
  • Works for DATE: WHERE dob BETWEEN '2004-01-01' AND '2004-12-31'. Quote dates.
  • Trap: thinking BETWEEN is exclusive. Trap: BETWEEN on a timestamp and missing the time part (00:00:00).
  • On the example next to this theory: BETWEEN — wHERE combines predicates with AND/OR; LIKE does pattern match.

Technical Interview Tip: WHERE marks BETWEEN 40 AND 60; → 40 and 60 both in.

Code Examples for BETWEEN

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

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

How to Explain BETWEEN to an Interviewer

Is BETWEEN inclusive?

Yes, both ends 40 AND 60 includes 40 and 60