© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
4 replies
Smardrengr

Query foreign table twice, once directly, once through join table

The docs https://supabase.com/docs/reference/javascript/select#query-foreign-tables-through-a-join-table almost get me there... But not quite. I need to query
profiles.name
profiles.name
for each
player
player
in a
game
game
. Not sure how to structure the
select()
select()
.

Here are the tables:
create table profiles (
  id uuid primary key references auth.users on delete cascade,
  name text,
  avatar_url text
);

create table games (
  id uuid primary key DEFAULT gen_random_uuid(),
  organizer_id uuid not null references profiles(id) on delete cascade,
  name text
);

create table players (
  id uuid primary key DEFAULT gen_random_uuid(),
  user_id uuid not null references profiles(id) on delete cascade,
  game_id uuid not null references games(id) on delete cascade
);
create table profiles (
  id uuid primary key references auth.users on delete cascade,
  name text,
  avatar_url text
);

create table games (
  id uuid primary key DEFAULT gen_random_uuid(),
  organizer_id uuid not null references profiles(id) on delete cascade,
  name text
);

create table players (
  id uuid primary key DEFAULT gen_random_uuid(),
  user_id uuid not null references profiles(id) on delete cascade,
  game_id uuid not null references games(id) on delete cascade
);

I can get the organizer's name
const { data: game } = await supabaseClient
        .from('games')
        .select('*,profiles(name, avatar_url)')
        .eq('id', event.params.id)
        .single();
const { data: game } = await supabaseClient
        .from('games')
        .select('*,profiles(name, avatar_url)')
        .eq('id', event.params.id)
        .single();

But how would I get the names of each
player
player
?
Supabase Documentation
Fetch data: select()
Fetch data: select()
Fetch data: select()
Supabase banner
SupabaseJoin
Supabase gives you the tools, documentation, and community that makes managing databases, authentication, and backend infrastructure a lot less overwhelming.
45,816Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Query table with multiple cols with same foreign key. Join tables.
SupabaseSSupabase / help-and-questions
3y ago
Join through another table
SupabaseSSupabase / help-and-questions
4y ago
Issue to query foreign tables
SupabaseSSupabase / help-and-questions
4y ago
Join table foreign table and return non-array for result
SupabaseSSupabase / help-and-questions
4y ago