# How to join the same table twice

**URL:** <https://community.omni.co/t/how-to-join-the-same-table-twice/46>\
**Category:** Modeling\
**Tags:** joins\
**Created:** [April 23, 2024, 5:27pm UTC](https://community.omni.co/t/how-to-join-the-same-table-twice/46 "2024-04-23T17:27:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![conor](https://yyz2.discourse-cdn.com/flex004/user_avatar/community.omni.co/conor/32/45_2.png) [@conor](https://community.omni.co/u/conor)\
**Post date:** [April 23, 2024, 5:27pm UTC](https://community.omni.co/t/how-to-join-the-same-table-twice/46/1 "2024-04-23T17:27:27Z")

</div>

When modeling topics, simplicity in naming conventions is key.

Our goal to make the BI layer self-serve beings with prioritizing ease of navigation for our end users.

**Aliasing joins** is a good start to build out tables of logical concepts. For this example they’ll be buyers and sellers.

Suppose we have an `orders` table containing fields such as `seller_id` and `buyer_id` , alongside a `users` table identified by an `id` key. To segment the `users` table into buyers and sellers, we need to join either the `buyer_id` or `seller_id` field with the `id` field in the `users` table. Essentially, we aim to join the _same tables_ twice but in _different manners_ each time. This is where **aliasing** comes in handy.

### Error we would see without the alias

If we try to make two joins without using aliasing we would reach a validation error.

```auto
Relationship duplication: there are multiple relationships between "order_items" and "users". This may lead to surprising results. Use a different alias for one of the relationships.

```

## 

 ![Screenshot 2024-04-23 at 11.37.54](https://canada1.discourse-cdn.com/flex004/uploads/omni/original/1X/30ea355065534dda99a442146d33de282b5dbd70.png)

## Solution: Use aliasing

To join the _same tables_ twice but in _different manners_ each time, we use aliasing.

In our relationships file we do the following:

Define the buyers join as:

```auto
# Define the buyers join
- join_from_view: order_items
  join_to_view: users
  join_to_view_as: buyers
  join_type: always_left
  on_sql: ${order_items.buyer_id} = ${buyers.id}
  relationship_type: assumed_many_to_one

```

Define the sellers join as:

```auto
# Define the sellers join
- join_from_view: order_items
  join_to_view: users
  join_to_view_as: sellers
  join_type: always_left
  on_sql: ${order_items.seller_id} = ${sellers.id}
  relationship_type: assumed_many_to_one

```

## Use the alias in the join on condition

It’s important to note that in the `on_sql:` block we are using the table alias as the prefix (`sellers`) in the join `${order_items.seller_id} = ${sellers.id}`.

---

<div class="post-metadata">

**Author:** ![Eric\_Hoffman](https://avatars.discourse-cdn.com/v4/letter/e/7993a0/32.png) [@Eric\_Hoffman](https://community.omni.co/u/Eric_Hoffman)\
**Post date:** [November 19, 2025, 1:45am UTC](https://community.omni.co/t/how-to-join-the-same-table-twice/46/2 "2025-11-19T01:45:38Z")

</div>

How do the fields for a topic appear in the field picker if there are two joins to the same table (one aliased)?

---

<div class="post-metadata">

**Author:** ![kylee](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@kylee](https://community.omni.co/u/kylee)\
**Post date:** [November 19, 2025, 1:46am UTC](https://community.omni.co/t/how-to-join-the-same-table-twice/46/3 "2025-11-19T01:46:44Z")

</div>

Hi Eric, the fields will be repeated under different view labels in the field picker.

---

<div class="post-metadata">

**Author:** ![Eric\_Hoffman](https://avatars.discourse-cdn.com/v4/letter/e/7993a0/32.png) [@Eric\_Hoffman](https://community.omni.co/u/Eric_Hoffman)\
**Post date:** [November 19, 2025, 1:53am UTC](https://community.omni.co/t/how-to-join-the-same-table-twice/46/4 "2025-11-19T01:53:42Z")

</div>

Hi Kylee, I’m not seeing that happening in my example. I have view\_label and group\_label set up for all my fields, will that impact this?

---

<div class="post-metadata">

**Author:** ![kylee](https://avatars.discourse-cdn.com/v4/letter/k/ea5d25/32.png) [@kylee](https://community.omni.co/u/kylee)\
**Post date:** [November 19, 2025, 1:58am UTC](https://community.omni.co/t/how-to-join-the-same-table-twice/46/5 "2025-11-19T01:58:00Z")

</div>

Hi Eric - sorry for not providing much nuance. My response is in the case of no other modeling being done like a view label or group label. The alias is essentially adding a view label so if you’re adding a view label separately, those fields will show up under the view label you assigned them to. If you’re wanting to do customizations on the fields in the aliased table you may find this [article](https://community.omni.co/t/extended-views-for-joining-the-same-table-with-different-logic/319) useful!
