© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•4y ago•
1 reply
avalanche8336

Join through another table

I have following tables:

  -- conversations
  create table if not exists public.conversation (
    id uuid not null primary key DEFAULT uuid_generate_v4(),
    sender_id uuid not null references auth.users (id) on delete cascade,
    receiver_id uuid not null references auth.users (id) on delete cascade,
    item_id uuid not null references public.item on delete cascade,
    created_at timestamp default timezone('utc', now()),
    unique(sender_id,receiver_id,item_id)
  );
  -- conversations
  create table if not exists public.conversation (
    id uuid not null primary key DEFAULT uuid_generate_v4(),
    sender_id uuid not null references auth.users (id) on delete cascade,
    receiver_id uuid not null references auth.users (id) on delete cascade,
    item_id uuid not null references public.item on delete cascade,
    created_at timestamp default timezone('utc', now()),
    unique(sender_id,receiver_id,item_id)
  );


 -- profiles
  create table if not exists public.profile (
    id uuid not null primary key DEFAULT uuid_generate_v4(),
    user_id uuid not null references auth.users (id) on delete cascade,
    image_url text default null,
    username text not null,
    currency_id bigint references public.currency not null,
    country_id bigint references public.country not null
  );
 -- profiles
  create table if not exists public.profile (
    id uuid not null primary key DEFAULT uuid_generate_v4(),
    user_id uuid not null references auth.users (id) on delete cascade,
    image_url text default null,
    username text not null,
    currency_id bigint references public.currency not null,
    country_id bigint references public.country not null
  );


and I want to join them through auth.users table on receiver_id and sender_id which are user id's, something like this but it doesn't work, can't find connection between profile and conversation tables:

    return _client
        .from(_conversationTable) //
        .select('''
            id,
            sender:profile(*)&profile.user_id=sender_id,
            receiver:profile(*)&profile.user_id=receiver_id,
            item:item_id(*),
            created_at
          ''')
        .eq('id', conversationId)
        .limit(1)
        .single()
        .execute()
    return _client
        .from(_conversationTable) //
        .select('''
            id,
            sender:profile(*)&profile.user_id=sender_id,
            receiver:profile(*)&profile.user_id=receiver_id,
            item:item_id(*),
            created_at
          ''')
        .eq('id', conversationId)
        .limit(1)
        .single()
        .execute()
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

Join between auth.users and another table
SupabaseSSupabase / help-and-questions
13mo ago
Query foreign table twice, once directly, once through join table
SupabaseSSupabase / help-and-questions
4y ago
search through table
SupabaseSSupabase / help-and-questions
3y ago
RLS With Join Table
SupabaseSSupabase / help-and-questions
4y ago