Understanding Correlated Subquery Execution Model
📖 Scenario: You are working with a small company database that stores information about employees and their departments. You want to find employees who earn more than the average salary of their own department.
🎯 Goal: Build a SQL query using a correlated subquery to list employees whose salary is greater than the average salary of their department.
📋 What You'll Learn
Create a table called
employees with columns id, name, department_id, and salary.Insert the exact employee data provided.
Write a correlated subquery that calculates the average salary per department.
Select employees earning more than their department's average salary.
💡 Why This Matters
🌍 Real World
Correlated subqueries are useful when you need to compare each row to a related set of rows, such as comparing an employee's salary to their department's average salary.
💼 Career
Understanding correlated subqueries helps in writing efficient and meaningful SQL queries for data analysis, reporting, and decision-making in many business roles.
Progress0 / 4 steps