• google plus

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:

  1. 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.
  2. Now let's explore the where clause and the operator words.
  3. Let's display city name and population where the population is between 1,000,000 and 2,000,000 people. Execute the following statement:
    Cities with population between 1 and 2 million
    You have included the where clause on your select statement with the between operator word. Rows with population values in the range of 1,000,000 to (and including) 2,000,000 will be selected.
  4. Now let's display the cities that have a state abbreviation of 'CA', 'FL' or 'NV':
    Cities in state abbrev CA, FL, NV
    The in operator word is used to define the set of state abbreviation values we want to select from the table.
Author: Stephen Withrow

Stephen has over 30 years' experience in training, development, and consulting in a variety of technology areas including Java, C, C++, XML, JavaScript, AJAX, Tomcat, JBoss, Oracle, and DB2. His background includes design and implementation of business solutions on client/server, Web, and enterprise platforms. Stephen is a published writer in both technical and non-technical endeavors. Stephen received an undergraduate degree in Computer Science and Physics from Florida State University.

About Webucator

Webucator provides instructor-led training to students throughout the US and Canada. We have trained over 90,000 students from over 16,000 organizations on technologies such as Microsoft ASP.NET, Microsoft Office, Azure, Windows, Java, Adobe, Python, SQL, JavaScript, Angular and much more. Check out our complete course catalog.