07
Chapter 7
JOINs (INNER, LEFT, RIGHT, FULL)
Combining tables. Inner, left, right, full, self, and the cross — knowing which one to reach for is most of the craft.
In this chapter
32
queries, easy → advanced
- 001INNER JOIN: employees with their department namesRead
- 002LEFT JOIN: all employees even if no departmentRead
- 003Get all products with their category namesRead
- 004Get all orders with customer namesRead
- 005Get order items with product names and order infoRead
- 006Self JOIN: find employee and their manager nameRead
- 007RIGHT JOIN: show all departments even without employeesRead
- 008FULL OUTER JOIN: all employees and departmentsRead
- 009CROSS JOIN: all employee-project combinationsRead
- 0104-table JOIN: order details with all infoRead
- 011Find employees assigned to projects with JOINRead
- 012Find departments with their total project budgetRead
- 013Employees NOT assigned to any project (anti-join)Read
- 014Find top customer per country using JOINRead
- 0155-table JOIN: full order reportRead
- 016Find employees who share same department AND managerRead
- 017LATERAL JOIN: employee with last salary changeRead
- 018NATURAL JOIN vs explicit JOIN (know the difference)Read
- 019Find products never ordered (LEFT anti-join)Read
- 020Recursive self-join: full org chart hierarchyRead
- 021Hierarchical query: find all subordinates of a managerRead
- 022Join employees with departments to get locationRead
- 023Get order total per customer with nameRead
- 024Find all items from a specific orderRead
- 025Get employee count and avg salary per locationRead
- 026Find customers who ordered product from specific categoryRead
- 027Employee project summary with total hoursRead
- 028Compare two periods: YoY revenue by categoryRead
- 029Employee who has worked on most projects in their departmentRead
- 030Sales report: customer, product, category, repRead
- 031Classic: consecutive login days per userRead
- 032USING clause in JOIN for cleaner syntaxRead