From the course: MySQL Data Analysis

Unlock this course with a free trial

Join today to access over 24,600 courses taught by industry experts.

Combining WHERE and OR

Combining WHERE and OR - MySQL Tutorial

From the course: MySQL Data Analysis

Combining WHERE and OR

- [Instructor] All right, so we've covered single-condition WHERE clauses and we've used AND to layer on additional filtering criteria. But what if we want our criteria to be a little more flexible? What if we're okay with returning data that satisfied criteria A or criteria B? That's where using WHERE and OR comes in. With OR, you can include multiple logical conditions in your WHERE clause. When you use OR, the server will return records which satisfy any of your criteria. So while adding additional AND criteria into your WHERE clause can only trim down your dataset, adding an additional criteria using or can actually make your results set get larger because there's another criteria and only one of the OR criteria must be satisfied. Here's a great pro tip: you can use AND and OR together in the WHERE clause. This is going to be really powerful once you learn how to do it. So let's take a look at this example. We're working with our payment data again, and this query is going to…

Contents