How to Find Managers with 5 or More Reports | SQL CTE vs Self Join | Leetcode Problem

Опубликовано: 30 Июнь 2026
на канале: Udit Singhal
115
3

Are you preparing for SQL interviews? This is the perfect video for you!
In this video, we solve a popular SQL interview question:
https://leetcode.com/problems/manager...
👉 Find all managers who have at least 5 direct reports

We’ll walk you through two different solutions:
✅ Using Common Table Expressions (CTE)
✅ Using a Self Join

Whether you're a beginner or brushing up for interviews, this video covers:
1. GROUP BY and COUNT(*) usage
2. Why managerId IS NOT NULL is critical
3. The difference between a subquery, CTE, and self join
4. When and why to use each approach

Check all SQL Videos here-
Introduction to SQL:    • Introduction to SQL  
SQL Syntax:    • SQL Syntax | SQL Tutorial for Beginners  
Creating Table SQL:    • Creating Table SQL | SQL Tutorial for Begi...  
SQL Select Statement:    • SQL Select Statement | SQL Tutorial for Be...  
SQL Select Distinct Statement:    • SQL Select Distinct Statement | SQL Tutori...  
SQL WHERE Statement:    • SQL WHERE Statement | SQL Tutorial for Beg...  
SQL ORDER BY:    • SQL ORDER BY | SQL Tutorial for Beginners  
SQL AND Operator:    • SQL AND Operator | SQL Tutorial for Beginners  
SQL OR Operator:    • SQL OR  Operator | SQL for Beginners  
SQL NOT Operator:    • SQL NOT Operator | SQL Tutorial for Beginners  
SQL MIN( ) & MAX( ) Functions:    • SQL MIN( )  & MAX( )  Functions | SQL Tuto...  
SQL COUNT Function:    • SQL COUNT Function | SQL Aggregate Functio...  
SQL SUM Function:    • SQL SUM Function | SQL Aggregate Function ...  
SQL Average Function:    • SQL Average Function | SQL Aggregate Funct...  
SQL LIKE Operator:    • SQL LIKE Operator | How to use wildcards S...  
SQL IN Operator:    • SQL IN Operator | How to use IN  Operator ...  
SQL BETWEEN Operator:    • SQL BETWEEN Operator | How to use BETWEEN ...  
SQL GROUP BY & HAVING Statement:    • SQL GROUP BY & HAVING Statement | How to u...  
SQL CASE WHEN Statement:    • SQL CASE WHEN Statement | How to use CASE ...  
SQL JOINS:    • SQL JOINS | Introduction to SQL JOINS | SQ...  
RANK Function in SQL:    • RANK Function in SQL | SQL Window Function  
DENSE RANK Functions in SQL:    • DENSE RANK Functions in SQL | SQL Window F...  
SQL ROW_NUMBER Function:    • SQL ROW_NUMBER Function | SQL Window Function  
SQL LAG and LEAD Functions:    • SQL LAG and LEAD Functions | Master SQL LE...  
SQL Left Join vs Right Join:    • SQL Joins Simplified - Left Join vs Right ...  
SQL UNION vs UNION ALL:    • UNION vs UNION ALL : SQL Basics You Must K...  
SQL EXISTS:    • SQL EXISTS Explained with Correlated Subqu...  
SQL Self Joins:    • Understand Self Joins in SQL Through a Man...  


#sqlinterviewquestions #sqltutorial #sqlforbeginners #sqltraining #leetcode ‪@welearnsql‬ #cte #databaseconcepts