Complex JOIN Conditions: Functions
Module: Joins & Relationships
SELECT * FROM orders o JOIN prices p ON o.product_id = p.product_id AND o.order_date BETWEEN p.start_date AND p.end_date;
Multiple conditions with AND/OR in ON clause
Can use non-equality operators (>, <, BETWEEN)
Can include computed values and functions
Conditions evaluated for each row combination
Order of conditions matters for performance
Core references in this topic include WHERE, =, != / <>. Learn what each one does, when to use it, and the execution or engine rules that matter.
WHERE
Filters rows before projection and sorting. It decides which rows continue through the query pipeline.
SELECT ... FROM table WHERE condition;
Most performance issues start with a weak WHERE clause or a missing supporting index.
=
Returns rows where the left and right values are exactly equal.
column = value
Use with exact matches. Do not use = NULL.
!= / <>
Returns rows where the compared values are not equal.
column <> value
SQL supports both <> and != in many engines, but <> is the portable form.
<, >, <=, >=
Range comparison operators for less-than, greater-than, and inclusive boundary checks.
salary >= 80000
AND
Requires every condition in the boolean expression to evaluate to TRUE.
condition_a AND condition_b
AND has higher precedence than OR.
OR
Matches rows when at least one condition is TRUE.
condition_a OR condition_b
Use parentheses when mixing OR with AND.
BETWEEN
Checks whether a value falls inside an inclusive lower/upper range.
order_total BETWEEN 100 AND 500
ANY / ALL
Compares one value against every or at least one value from a subquery result.
salary > ALL (SELECT salary FROM interns)
DATE
Stores a calendar date without any time-of-day component.
DATE '2026-04-18'
INTERVAL