Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

BETWEEN Conditional Expression

Description

The BETWEEN conditional expression makes a comparison to determine whether the data value on the left exists between two data values specified on the right. It returns TRUE even when the data value on the left is the same as a boundary value of the comparison target range. If NOT comes before the BETWEEN keyword, the result of a NOT operation on the result of the BETWEEN operation is returned.

i BETWEEN g AND m and the compound condition i >= g AND i <= m have the same effect.

Syntax

expression [ NOT ] BETWEEN expression AND expression

  • expression : A column name, path expression, constant value, arithmetic expression or aggregate function can be used. For a character string expression, the conditions are evaluated in alphabetical order. If NULL is specified for at least one of the expressions, the BETWEEN predicate returns UNKNOWN as the result.
Example

--selecting rows where 3000000 <= salary <= 4000000

SELECT * FROM condition_tbl WHERE salary BETWEEN 3000000 AND 4000000;

 

SELECT * FROM condition_tbl WHERE (salary >= 3000000) AND (salary <= 4000000);

           id  name                  dept_name                  salary

======================================================================

            1  'Kim       '          'devel'                   4000000

            2  'Moy       '          'sales'                   3000000

            5  'Kim       '          'account'                 3800000

 

--selecting rows where salary < 3000000 or salary > 4000000

SELECT * FROM condition_tbl WHERE salary NOT BETWEEN 3000000 AND 4000000;

           id  name                  dept_name                  salary

======================================================================

            3  'Jones     '          'sales'                   5400000

            4  'Smith     '          'devel'                   5500000

            6  'Smith     '          'devel'                   2400000

 

--selecting rows where name starts from A to E

SELECT * FROM condition_tbl WHERE name BETWEEN 'A' AND 'E';

           id  name                  dept_name                  salary

======================================================================

            7  'Brown     '          'account'                    NULL