From the course: MySQL Data Analysis

Unlock this course with a free trial

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

Combining WHERE and IN

Combining WHERE and IN - MySQL Tutorial

From the course: MySQL Data Analysis

Combining WHERE and IN

- [Instructor] All right, next, let's talk about using IN in your WHERE condition. Anytime you find yourself writing multiple OR conditions which are referencing different values in the same column, you could use IN, which is a great little shortcut. Here's the query from our last exercise. See how we've got four separate customer_id equals OR conditions? Now take a look at this other query. The only difference in the queries are the portions highlighted in green here. In the first query, we've written out four separate lines, OR customer_id equals with a specific value. In the second query, we've collapsed all four of those values into one single line by using the IN operator. These two queries do the exact same thing. The results produced are identical, but the second query is a lot faster to write, and it's a lot easier to read. My pro tip for using IN is use it all the time. Don't ever write queries like the ones at the top. Anytime you see yourself repeating the same column with…

Contents