2.10.2.5.10. JPQL Between Expressions

The syntax for the use of the comparison operator [ NOT ] BETWEEN in a conditional expression is as follows:

arithmetic_expression [NOT] BETWEEN arithmetic_expression AND arithmetic_expression | string_expression [NOT] BETWEEN string_expression AND string_expression | datetime_expression [NOT] BETWEEN datetime_expression AND datetime_expression

The BETWEEN expression

x BETWEEN y AND z

is semantically equivalent to:

y = x AND x = z

The rules for unknown and NULL values in comparison operations apply. See JPQL Null Values .

Examples are:

p.age BETWEEN 15 and 19

is equivalent to:

p.age = 15 AND p.age = 19

The following expression:

p.age NOT BETWEEN 15 and 19

excludes the range, and is equivalent to:

p.age  15 OR p.age  19

In the following example, transactionHistory is a list of credit card transactions defined using an order column.

SELECT t
FROM CreditCard c JOIN c.transactionHistory t
WHERE c.holder.name = ‘John Doe’ AND INDEX(t) BETWEEN 0 AND 9