From the course: Database Foundations: Data Structures

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Self-referencing relationships

Self-referencing relationships

From the course: Database Foundations: Data Structures

Start my 1-month free trial

Self-referencing relationships

- [Narrator] Relationships are almost always made between two different data tables. But it is possible for a column in a table to relate to another column in the same table. This is called a self-referencing relationship. A self-reference also known as a self-join or a recursive relationship follows all of the same rules as the relationships created between two tables. They can be one-to-one, one-to-many or many-to-many. The same unique constraints still apply and will dictate the type of relationship made. The only difference is that both columns are in the same table instead of two different tables, which sets up a hierarchy that can loop back on itself. So where might a self-reference be useful? They're used to model hierarchies within the same class. So for instance consider this table of employees. Each employee has an ID and the table also stores the ID of the employee's direct supervisor. If you mentally connect to…

Contents