# Self Join Scenario

**URL:** <https://forum.data-community.org/t/self-join-scenario/1543>\
**Category:** Data Vault 2.0\
**Created:** [October 8, 2024, 9:54am UTC](https://forum.data-community.org/t/self-join-scenario/1543 "2024-10-08T09:54:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![kvs.naidu](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kvs.naidu](https://forum.data-community.org/u/kvs.naidu)\
**Post date:** [October 8, 2024, 9:54am UTC](https://forum.data-community.org/t/self-join-scenario/1543/1 "2024-10-08T09:54:16Z")

</div>

Hai,  
I have a table which references with itself know as self join.  
I have an employee table where emp\_id is primary key. another column called manager\_id which is referencing to emp\_id only. becoz manager also employee in the organization.  
how can we generate hub and link structures in this situation ?

---

<div class="post-metadata">

**Author:** ![patrickcuba](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.data-community.org/patrickcuba/32/19_2.png) [@patrickcuba](https://forum.data-community.org/u/patrickcuba)\
**Post date:** [October 8, 2024, 9:19pm UTC](https://forum.data-community.org/t/self-join-scenario/1543/2 "2024-10-08T21:19:07Z")

</div>

you just answered your own question, hierarchical link joins the same hub table… nuff said

---

<div class="post-metadata">

**Author:** ![SheriDH](https://avatars.discourse-cdn.com/v4/letter/s/7cd45c/32.png) [@SheriDH](https://forum.data-community.org/u/SheriDH)\
**Post date:** [October 16, 2024, 1:23pm UTC](https://forum.data-community.org/t/self-join-scenario/1543/3 "2024-10-16T13:23:17Z")

</div>

When loading the employee table into the data vault structure, you would have 2 hub entries (one or both may already exist) : emp\_id and emp\_id (mgr\_id). The link table would have both keys. I think it’s a choice as to whether the order of the keys in the link implies the relationship (hazardous) or there is an attribute on the link that identifies the nature of the relationship. (the latter is more robust as it could potentially allow for other types of relationships between employees.)

---

<div class="post-metadata">

**Author:** ![patrickcuba](https://dub1.discourse-cdn.com/flex013/user_avatar/forum.data-community.org/patrickcuba/32/19_2.png) [@patrickcuba](https://forum.data-community.org/u/patrickcuba)\
**Post date:** [October 20, 2024, 11:17pm UTC](https://forum.data-community.org/t/self-join-scenario/1543/4 "2024-10-20T23:17:21Z")

</div>

Mate… think about how the link will look like when joining to the same hub

Link-HashKey: dv\_hashkey\_link\_emp\_mgr  
Hub-HashKey1: dv\_hashkey\_hub\_employee  
Hub-HashKey2: dv\_hashkey\_hub\_manager

Why do you need another column to indicate which is the manager and which is the employee?
