Entering content frame

BETWEEN predicate (between_predicate) 

The BETWEEN predicate ( between_predicate) checks whether a value is within a specified range.

Syntax

<between_predicate> ::= <expression> [NOT] BETWEEN <expression> AND <expression>

expression

Explanation

Let x, y, and z be the results of the first, second, and third expression. The values x,y,z must be comparable.

 

 

Result of the specified predicate

x BETWEEN y AND z

x>=y AND x<=z

x NOT BETWEEN y AND z

NOT(x BETWEEN y AND z)

x, y, or z are NULL values

x [NOT] BETWEEN y AND z is undefined

Example table: customer

Finding customers with a credit balance between –420 and 0:

SELECT title, name, city, account FROM customer
WHERE account BETWEEN -420 AND 0

TITLE

NAME

CITY

ACCOUNT

Mr

Porter

Los Angeles

0.00

Mrs

Peters

Los Angeles

0.00

Mr

Brown

Hollywood

0.00

Mr

Porter

New York

0.00

Mr

Howe

New York

-315.40

Mr

Randolph

Los Angeles

0.00

Mr

Jackson

Los Angeles

0.00

Mr

Adams

Los Angeles

-416.88

Mr

Griffith

New York

0.00

You want to list the customers who have either a credit balance or a significant debit balance:

SELECT title, name, city, account FROM customer
WHERE account NOT BETWEEN -10 AND 0

TITLE

NAME

CITY

ACCOUNT

Mrs

Porter

New York

100.00

Comp

DATASOFT

Dallas

4813.50

Mr

Howe

New York

-315.40

Mr

Peters

Los Angeles

650.00

Mrs

Brown

Los Angeles

-4167.79

Mr

Adams

Los Angeles

-416.88

Comp

TOOLware

Los Angeles

3770.50

Mrs

Brown

Hollywood

440.00

 

 

Leaving content frame