How to Use the WHERE Clause and Operator Words
The SQL select statement where clause can be used to select rows by means of operator words. For example, we can specify a range of values using "between" or a set of values using "in".
To learn how to use the where clause and its associated operator words on an SQL select statement, follow these steps:
- You'll need to setup the MySQL database tables. The instructions for the setup can be found in How to add comments in simple SQL selects. Follow steps 1 through 7 in this topic before proceeding to the next step.
- Now let's explore the where clause and the operator words.
- Let's display city name and population where the population is between 1,000,000 and 2,000,000 people. Execute the following statement:
You have included the where clause on your select statement with the
betweenoperator word. Rows with population values in the range of 1,000,000 to (and including) 2,000,000 will be selected.
- Now let's display the cities that have a state abbreviation of 'CA', 'FL' or 'NV':
inoperator word is used to define the set of state abbreviation values we want to select from the table.