# Joining non-foreign keyed tables in Supabase

**URL:** <https://community.weweb.io/t/joining-non-foreign-keyed-tables-in-supabase/18921>\
**Category:** How do I?\
**Tags:** supabase\
**Created:** [June 24, 2025, 8:57am UTC](https://community.weweb.io/t/joining-non-foreign-keyed-tables-in-supabase/18921 "2025-06-24T08:57:12Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![oli](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/oli/32/8397_2.png) [@oli](https://community.weweb.io/u/oli)\
**Post date:** [June 24, 2025, 8:57am UTC](https://community.weweb.io/t/joining-non-foreign-keyed-tables-in-supabase/18921/1 "2025-06-24T08:57:12Z")

</div>

Hi folks, I have a question about using the Supabase plug to join together two tables that aren’t foreign keyed. I have

1. A user table, with a UUID field
2. A tags table, where there is a record\_id field that a) contains the user.id and b) isn’t fkeyed to the user table (because it’s used across multiple tables)

From my playing around, I can’t get the advanced query builder in the SB plugin to link these two tables, because there’s no connection that WeWeb understands. But there is a unique ID that will link the two tables via a traditional SQL query.

Is there a way round this? I’ve used SB views but found them to be very slow when loading compared to using the SB plugin.

Hope I’ve explained this well enough, let me know if you need more detail!

---

<div class="post-metadata">

**Author:** ![tomerer2000](https://avatars.discourse-cdn.com/v4/letter/t/9d8465/32.png) [@tomerer2000](https://community.weweb.io/u/tomerer2000)\
**Post date:** [June 24, 2025, 9:06am UTC](https://community.weweb.io/t/joining-non-foreign-keyed-tables-in-supabase/18921/2 "2025-06-24T09:06:23Z")

</div>

Use supabase functions, as it sounds like pretty simple sql query, and ai probably can code it for you pretty easily  
And also there is this supabase video for multi keys

[![](https://us1.discourse-cdn.com/flex016/uploads/weweb/original/2X/0/057c279c7a69b4235f459c4beca8b1a8eaa6a9ca.jpeg "One to Many Relationship - SupabaseTips") ](https://www.youtube.com/watch?v=5VrF9OVQ6rg)

---

<div class="post-metadata">

**Author:** ![Broberto](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/broberto/32/5918_2.png) [@Broberto](https://community.weweb.io/u/Broberto)\
**Post date:** [June 24, 2025, 9:21am UTC](https://community.weweb.io/t/joining-non-foreign-keyed-tables-in-supabase/18921/3 "2025-06-24T09:21:22Z")

</div>

> [@oli](#):
>
> because it’s used across multiple tables

What?? 😃 Are you aware you can use foreign keys on as many tables as you want? Or maybe I’m understanding it incorrectly?

---

<div class="post-metadata">

**Author:** ![oli](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/oli/32/8397_2.png) [@oli](https://community.weweb.io/u/oli)\
**Post date:** [June 24, 2025, 10:32am UTC](https://community.weweb.io/t/joining-non-foreign-keyed-tables-in-supabase/18921/4 "2025-06-24T10:32:12Z")

</div>

As in, there’s two fields on the “tags” table:

- Field 1: table\_name
- Field 2: record\_id

It’s designed so that when we’re linking a tag, it can be linked to any table we want it to. So in the second field, you could have IDs of records from a bunch of different tables.

---

<div class="post-metadata">

**Author:** ![oli](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/oli/32/8397_2.png) [@oli](https://community.weweb.io/u/oli)\
**Post date:** [June 24, 2025, 10:32am UTC](https://community.weweb.io/t/joining-non-foreign-keyed-tables-in-supabase/18921/5 "2025-06-24T10:32:29Z")

</div>

Thank you! Will investigate.

---

<div class="post-metadata">

**Author:** ![oli](https://sea2.discourse-cdn.com/flex016/user_avatar/community.weweb.io/oli/32/8397_2.png) [@oli](https://community.weweb.io/u/oli)\
**Post date:** [June 24, 2025, 12:58pm UTC](https://community.weweb.io/t/joining-non-foreign-keyed-tables-in-supabase/18921/6 "2025-06-24T12:58:38Z")

</div>

For anyone reading this - I tried making a view again (using Supabase’s AI SQL generator) and asked it to make it as performant as possible. And it works wayyyyy better than than the mega query from WeWeb. So I think there’s just a point where if you have too many joins / too much data the simplest thing is to do a view, and beyond that it’s an edge function. Still learning!
