Comparison operators  Lists (in and not in)

Chapter 2: Queries: Selecting Data from a Table

Ranges (between and not between)

Use the between keyword to specify an inclusive range.

For example, to find all the books with sales between and including 4095 and 12,000, you can write this query:

select title_id, total_sales 
from titles 
where total_sales between 4095 and 12000 
title_id  total_sales 
------    -----------
BU1032           4095 
BU7832           4095 
PC1035           8780 
PC8888           4095 
TC7777           4095 
 
(5 rows affected) 

You can specify an exclusive range with the greater than (>) and less than (<) operators:

select title_id, total_sales 
from titles 
where total_sales > 4095 and total_sales < 12000 
title_id  total_sales 
------    -----------
PC1035           8780 
 
(1 row affected)

not between finds all rows outside the specified range. To find all the books with sales outside the $4095 to $12,000 range, type:

select title_id, total_sales 
from titles 
where total_sales not between 4095 and 12000
title_id     total_sales 
--------     -----------
BU1111              3876 
BU2075             18722 
MC2222              2032 
MC3021             22246 
PS1372               375 
PS2091              2045 
PS2106               111 
PS3333              4072 
PS7777              3336 
TC3218               375 
TC4203             15096 
 
(11 rows affected) 




Copyright © 2005. Sybase Inc. All rights reserved. Lists (in and not in)

View this book as PDF