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 - 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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
(Locked)
Output row numbers with query results2m 29s
-
(Locked)
Cast values to a different data type2m 15s
-
(Locked)
Move rows within a result with LEAD and LAG5m 47s
-
(Locked)
Use an IN function with a subquery4m 7s
-
(Locked)
Define WHERE criteria with a series4m 30s
-
(Locked)
Solution: Calculations across rows4m 19s
-
(Locked)
Pattern matching with regular expressions6m 57s
-
(Locked)
-