How to Check Multiple Conditions in SQL

A select statement in SQL may contain one or more conditions (also known as predicates) in the where clause. A condition evaluates to true or false or unknown. The where clause must return a true value for a particular row to be selected.

To learn how to check multiple conditions in a 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 its conditions.
  3. Suppose we want to display cities whose population is between 1,000,000 and 5,000,000 people or that are located in Nevada (state abbreviation = 'NV'). Execute the following statement:
    Cities with population between 1 and 5 million or NV
    Two conditions are present in the where clause. The conditions are separated by the or keyword. Either condition can be true in order for the row to be selected.
  4. Our next requirement is to display cities in California (state abbreviation = 'CA') only where the population is between 1,000,000 and 5,000,000 people:
    Cities in state abbrev CA, FL, NV
    Again, two conditions are present in the where clause but now the conditions are separated by the and keyword. Both conditions must be true in order for the row to be selected.
Author: Stephen Withrow

Stephen has over 30 years of experience in training, development, and consulting in a variety of technology areas including Python, Java, C, C++, XML, JavaScript, Tomcat, JBoss, Oracle, and DB2. His background includes design and implementation of business solutions on client/server, Web, and enterprise platforms. Stephen has a 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.