A reflexive join (also known as a self-join) is the join of a table to itself. For example, typically employees and managers are stored in the same table since all of the individuals are ultimately employees. The manager ID is stored as a foreign key in each employee row and references the same table.
To learn how to use reflexive joins, follow these steps:
Employeestable. Execute the following select:
colcommand to limit column width to make the report more readable. Also note that I have displayed the first part of the output that contains 106 employees overall. I have highlighted the reflexive join that references the
Employeestable on either side of the
inner joinkeywords. The first reference treats the table as an employees table and second reference treats the table as a managers table. The
onclause matches an employee with his or her manager.