Day 34 — 8 more Hard JOIN questions (93/100)
Finished 8 more Hard questions from my 100-question lab today. Some of the ones I worked through:
- Pairs of employees who are in different departments but work on the same project together. I self-joined
assignmentsonproject_idand useda1.emp_id < a2.emp_idto stop mirrored duplicates (A-B and B-A), then joined toemployeestwice and filterede1.dept_id <> e2.dept_id - Departments ranked by average hours worked per employee, which chains departments → employees → assignments and aggregates by department
- Employees whose manager works in a different department than they do, a self-join on
employeescomparingdept_idon both sides
The < trick for removing mirrored pairs was new to me today. I’d been using DISTINCT for that kind of thing, and this is cleaner.
7 left. Does anyone have a favorite pattern for ranking queries in MySQL? I haven’t done window functions properly yet and wondering if they’d make the “ranked by” questions easier.