Connecting Data for Insights

Subqueries for Smarter Data Access

Learning Outcome

5

Differentiate between subqueries and joins

4

Apply correlated subqueries for dynamic filtering

3

Use subqueries in WHERE, FROM, and SELECT clauses

2

Identify different types of subqueries

1

Define and explain subqueries

Recall

  • INNER JOIN → Only common records from both tables
  • LEFT JOIN → All left table + matched right table records
  • RIGHT JOIN → All right table + matched left table records
  • FULL JOIN (OUTER JOIN) → All records from both tables (matched + unmatched)

You Open Instagram

Instagram calculates the average number of followers across users.

Then it compares each user’s followers with that average.

Instead of running two separate queries manually, SQL can do this in a single query using a subquery.

SELECT username, followers
FROM users
WHERE followers > (
    SELECT AVG(followers)
    FROM users );

Transition to concept

This is exactly how subqueries work
they help us connect data and generate smarter insights in one step.

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (Slide 7)

Core Concepts (.....Slide N-3)

Summary

5

Powerful for insight generation

4

Correlated subqueries execute per row

3

Can appear in WHERE, FROM, SELECT

2

Used for dynamic filtering and logical separation

1

Subqueries are queries inside queries

Quiz

Which clause can contain a subquery?

A. WHERE

B. FROM

C. SELECT

D. All of the above

Quiz-Answer

Which clause can contain a subquery?

A. WHERE

B. FROM

C. SELECT

D. All of the above

Connecting Data for Insights: Subqueries for Smarter Data Access

By Content ITV

Connecting Data for Insights: Subqueries for Smarter Data Access

  • 9