Often in SQL, retrieving the desired data depends more upon matching multiple values than it does on matching a single value. SQL allows us to do this in several different ways. In this section, we examine the use of range conditions, set conditions, pattern-matching, and Boolean operators.
Say that we want a list of the employees who have logged in to the Companylink site. However, we want to restrict this list to only those who have logged in at least 1,000 times, but no more than 2,000 times. Using what we know of WHERE
clauses so far, how would we do this? We actually have two conditions that must be met for our result set to meet our requirements. There are multiple ways we could do this, including Boolean conditions, but, for now, we examine the use of a new clause—the BETWEEN
clause:
While the syntax of the BETWEEN
clause is fairly natural sounding, it's important to understand several points...