Beginner

665. JOIN Condition with BETWEEN

Use BETWEEN in JOIN conditions when a value must fall within a defined range.

📘 Lesson 665 of 728 ⏱ 14 min 🎯 Advanced

BETWEEN checks whether a value falls inclusively between two boundary values and can be used in JOIN conditions.

Range-based business rules frequently require matching a value to a defined interval.

Match an employee's salary to a salary grade.

SQL
SELECT
    e.EmployeeName,
    e.Salary,
    g.GradeName
FROM Employees e
INNER JOIN SalaryGrades g
    ON e.Salary BETWEEN g.MinSalary AND g.MaxSalary;

Used in salary bands, tax slabs, pricing tiers, risk categories, and commission structures.

  • BETWEEN includes both boundaries.
  • It can be used inside JOIN conditions.
  • Boundary overlaps can create duplicate matches.
  • Careful range design is important.
  • For dates, half-open ranges can sometimes be safer.
Can BETWEEN be used in a JOIN?

Yes. BETWEEN can match a value against a range in another table.

Are BETWEEN boundaries inclusive?

Yes. BETWEEN includes both the lower and upper boundary.

Have you finished this lesson?

Introduction to SQL – All Lessons