Slide 14.17: The IN operator Slide 14.19: Aliases Home |
BETWEEN
Operator
BETWEEN ... AND
operator selects a range of data between two values.
These values can be numbers, text, or dates.
SELECT column_name FROM table_name WHERE column_name BETWEEN value1 AND value2 |
LastName | FirstName | Address | City |
---|---|---|---|
Hansen | Ola | Timoteivn 10 | Sandnes |
Nordmann | Anna | Neset 18 | Sandnes |
Pettersen | Kari | Storgt 20 | Stavanger |
Svendson | Tove | Borgvn 23 | Sandnes |
SQL> select * from Persons 2 where LastName between 'Hansen' and 'Pettersen'; |
LastName | FirstName | Address | City |
---|---|---|---|
Hansen | Ola | Timoteivn 10 | Sandnes |
Nordmann | Anna | Neset 18 | Sandnes |
Pettersen | Kari | Storgt 20 | Stavanger |
NOT
operator:
SQL> select * from Persons 2 where LastName not between 'Hansen' and 'Pettersen'; |
LastName | FirstName | Address | City |
---|---|---|---|
Svendson | Tove | Borgvn 23 | Sandnes |
Customers
table may be created by the following command:
SQL> create table Customers ( 2 CustomerID varchar(16), 3 CompanyName varchar(32), 4 ContactName varchar(32), 5 Address varchar(64), 6 City varchar(32), 7 PostalCode varchar(16), 8 Country varchar(32) );Note that the
Customers
table is for read only.