How to Check Multiple Conditions in SQL

See SQL: Tips and Tricks for similar articles.
Looking to improve your SQL skills? Check out Webucator’s SQL classes.

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, NVAgain, 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.

Related Articles

  1. Reset Root Password in MySQL on Windows
  2. How to Create an ER Diagram for a MySQL Database with Free Tools
  3. How to Round Up in SQL
  4. How to Concatenate Strings in SQL
  5. How to Select All Columns in a Row in SQL
  6. How to Check Multiple Conditions in SQL (this article)
  7. How Work with White Space and Semicolons in Simple SQL Selects
  8. How to Sort Records in SQL
  9. How to Write Subqueries (Simple and Correlated)