SQL Advanced (Analytics)
🎯 Free Guest Mode: You are learning for free. Sign in to save your completion progress and quiz answers.
Loading progress...

Key moments

  1. Subquery Overview and Setup — Defines subqueries and introduces the sample EmployeeSalary dataset.
  2. Subqueries in SELECT Clause — Demonstrates calculating and appending overall average salary to row-level employee data.
  3. Window Function Comparison — Compares SELECT subquery output with AVG() OVER() and explains why GROUP BY fails here.
  4. Subqueries in FROM Clause — Builds a derived table subquery in FROM and compares it against CTEs and temp tables.
  5. Subqueries in WHERE Clause — Filters salary records based on age criteria from EmployeeDemographics using WHERE IN.
PDF notes

Frequently asked questions

Can I use SELECT * inside a WHERE IN subquery?

No, the WHERE IN operator expects a single column of values to match against the outer column. Returning multiple columns will throw a database syntax error.

When should I prefer CTEs or temp tables over FROM subqueries?

Prefer CTEs and temp tables when query logic is complex or reused across multiple steps, as FROM subqueries cannot be referenced multiple times and quickly become unreadable.

How does a SELECT subquery differ from AVG() OVER()?

Both return identical overall average results alongside row data, but window functions are native analytical constructs that are typically cleaner and more performant.

How was this lesson?

Your feedback helps us refine explanations and catch bugs.