Boolean — SQL Technical Interview Questions & Answers

Boolean

Boolean

  • MySQL treats 0 as false and 1 (or non-zero) as true in many boolean contexts. A TINYINT(1) column is a common ‘boolean’. TRUE and FALSE are aliases for 1 and 0.
  • WHERE passed; means WHERE passed <> 0. Prefer WHERE passed = 1 so readers don’t guess.
  • Trap: storing ‘yes’/‘no’ strings and comparing to TRUE.
  • On the example next to this theory: Boolean — wHERE combines predicates with AND/OR; LIKE does pattern match.

Technical Interview Tip: TINYINT(1) as 0/1. WHERE passed = 1;

Code Examples for Boolean

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

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

How to Explain Boolean to an Interviewer

How does MySQL store true/false?

Often TINYINT 0/1 TRUE is 1