From the course: PostgreSQL: Advanced Queries

Unlock the full course today

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

Use an IN function with a subquery

Use an IN function with a subquery - PostgreSQL Tutorial

From the course: PostgreSQL: Advanced Queries

Use an IN function with a subquery

- [Instructor] When filtering the results of a query using a where clause, you might find yourself listing out multiple criteria for the same column. For instance, let's suppose that I wanted to take a look at some product data. If I only wanted to see products with three specific names, I could write out the where clause like this, where our product_name is equal to Delicate, or product_name is equal to Bold, or product_name equals Light. The results of this query will show me exactly those items. Here are all of my delicate items, my bold items below. And if I scroll to the end, we'll see all of the Light items. A more streamlined approach that'll get the exact same result is to use a function called in. The in function takes a list of items and it'll compare the column against every item in the list. So all of these or lines will get rewritten like this with an in function. We can say where product_name in, open a…

Contents