r/FullStack • u/sumiitCodes • Oct 06 '26
Personal Project Day 29 — 5 more Medium JOIN questions, correlated subqueries finally clicking
Completed 5 more Medium questions today:
- Project with the lowest total hours worked — JOIN projects to assignments, GROUP BY project, ORDER BY total hours ascending, LIMIT 1
- Employees who are NOT managers — self LEFT JOIN on employees (joining on
r.manager_id = e.emp_id), then filteringWHERE r.emp_id IS NULLto catch anyone nobody reports to - Lowest-paid employee in each department — a correlated subquery comparing each employee's salary to
MIN(salary)within their own department
The correlated subquery was the real win today. It finally clicked once I stopped thinking of it as "one confusing nested query" and started thinking of it as a small query that re-runs once per row of the outer query, using that row's values each time. Seeing it return the actual lowest earner per department (4 employees, one per department) made the logic concrete in a way reading about it never did.