A RANGE JOIN matches a value from one table against a minimum and maximum range stored in another table.
Many business rules are represented as ranges rather than exact values.
Assign each employee a salary grade based on their salary range.
SELECT
e.EmployeeName,
e.Salary,
g.Grade
FROM Employees e
JOIN SalaryGrades g
ON e.Salary >= g.MinSalary
AND e.Salary <= g.MaxSalary;
Range joins are useful for salary grades, tax calculations, commission rates, pricing tiers, risk scoring, and date validity periods.
- Range JOINs match values against intervals.
- Minimum and maximum boundaries define the range.
- BETWEEN can simplify range conditions.
- Ranges should be designed carefully.
- Overlapping ranges can create duplicate matches.
What is a RANGE JOIN?
A RANGE JOIN matches a value from one table against a defined interval in another table.
What problem can overlapping ranges cause?
Overlapping ranges can cause one record to match multiple rows and produce duplicate results.