SQL Saturday #01
OR vs IN
SQL Saturday · 2026-11-28
The Question
Your boss has asked you to pull payment records for a specific list of customer accounts (73, 43, 53, 60) plus any payments over $5.00
The Data:
Table: PaymentColumn: p.customer_idColumn: p.rental_idColumn: p.amountColumn: p.payment_date
The Query
Query #1
SELECT
p.customer_id,
p.rental_id,
p.amount,
p.payment_date
FROM payment p
WHERE p.amount > 5
OR p.customer_id = 73
OR p.customer_id = 43
OR p.customer_id = 53
OR p.customer_id = 60
Query #2
SELECT
p.customer_id,
p.rental_id,
p.amount,
p.payment_date
FROM payment p
WHERE p.amount > 5
OR p.customer_id IN (73,43,53,60)
The Takeaway
Both queries are valid and will return the same results. The second query is much more convenient, easier to read and quicker to write. Whenever you find yourself writing repeated OR clauses, think about cleaning up the query by using IN rather than consecutive OR's.
Be careful when considering mixing AND with OR. AND is evaluated before OR, so adding AND p.payment_date >= '2026-01-01' to the end of Query #1 would only apply the date filter to customer 60. Using IN keeps the customer list in a single condition, and wrapping OR conditions in parentheses makes the logic explicit.