Memra

Combining conditions: AND, OR, BETWEEN, IN

◈ 3 cards

Build richer filters from simple ones.

Combine conditions

Join conditions with AND (both true) and OR (either true). Use parentheses when you mix them:

SELECT title FROM books
WHERE genre = 'fiction' AND price < 15;

Two shorthands save typing:

  • BETWEEN a AND b — inclusive range: price BETWEEN 10 AND 20.
  • IN (...) — matches any value in a list: genre IN ('poetry', 'history').

Both read better than the long OR chains they replace.

shorthandlong formon our dataprice BETWEEN 10 AND 20price >= 10 AND price <= 20both ends includedgenre IN('poetry','history')genre = 'poetry' OR genre ='history'4 booksSame meaning, less to misread.
Neither shorthand adds power — they compile to the same comparisons. They earn their place by staying readable as the list of values grows.
NORMAL ~/memra/learn/postgresql/boolean-logic-ranges utf-8 LF