SQL tutorial
文章来源: 漂泊一族2006-06-09 22:12:48
The IN operator may be used if you knowthe exact value you want to return for at least one of the columns. To display the persons with LastName equal to "Hansen" or "Pettersen", use the following SQL:
SELECT * FROM Persons WHERE LastName IN ('Hansen', 'Pettersen')

The BETWEEN...AND operator selects a range of data between two values. To display the persons alphabetically between (including) "Hansen" and exclusive "Pettersen", use the following SQL:
SELECT * FROM Persons WHERE LastName BETWEEN 'Hansen' AND 'Pettersen'

The BETWEEN...AND operator is treated differently in different databases. Some only selects fields that are between and excluding the test values. Some selects fields that are between and including the test values. Some selects fields between the test values, including the first test value and excluding the last test value.

To display the persons outside the range used in the previous example, use the NOT operator:
SELECT * FROM Persons WHERE LastName NOT BETWEEN 'Hansen' AND 'Pettersen'