MySQL SQLLesson 33Free preview
MySQL Self Join
This lesson is part of MySQL · All levels
Summary
Self join is the merging of a table with itself, which is usually done by giving two different aliases to the same table. This technique is used when a table represents hierarchical relationships, for example employees with superiors who are also employees, or categories with category masters. Although the table names are the same, both aliases are required for MySQL to distinguish between the left and right sides.
Key points
- Self join uses the same table twice with two different aliases
- The ON condition compares the column to itself, for example e.id = m.id_manager
- Suitable for hierarchical data such as top-down or parent-child categories
- Self join makes special syntax, just the usual use of INNER JOIN
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.