expression BETWEEN min AND max

Description: Returns 1 if expression is greater than or equal to min and less than or equal to max; 0 otherwise.

The comparison is performed according to the following rules:

  • If expression is a TIMESTAMP, DATE, or DATETIME column, min and max are interpreted as the same datatype if they are constants.

  • If expression is a string that is not case-sensitive, the comparison is done in a way that is not case-sensitive.

  • If expression is a string that is case-sensitive, the comparison is done in a case-sensitive way.

  • If expression is evaluated to be an integer, an integer comparison is done.

  • Otherwise, a floating-point comparison is done.

Examples:

  • 10 BETWEEN 12 AND 20 returns 0.

  • 10 BETWEEN '10' AND '20' returns 1.

  • 'a' BETWEEN ...

Get Sams Teach Yourself MySQL in 21 Days, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.