© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3mo ago•
9 replies
cesar

Querying Joins and Nested tables issue

🟡javascript
I'm having an many-to-one issue on a query that I can't solve. Giving:
create table profiles {
  "id" uuid primary key,
  -- ...
  "created_by" uuid references profiles, -- profiles_created_by_profiles_id_fk
  "updated_by" uuid references profiles -- profiles_updated_by_profiles_id_fk
};

create view profiles_with_crew_owner_home_places as (
  select p.id as profile_id
  -- ....
);
create table profiles {
  "id" uuid primary key,
  -- ...
  "created_by" uuid references profiles, -- profiles_created_by_profiles_id_fk
  "updated_by" uuid references profiles -- profiles_updated_by_profiles_id_fk
};

create view profiles_with_crew_owner_home_places as (
  select p.id as profile_id
  -- ....
);

I need to reproduce the query below using supabase client syntax:
select p.id, q.profile_id from profiles as p
join profiles_with_crew_owner_home_places as q on p.id = q.profile_id
where p.id = 'abc';
select p.id, q.profile_id from profiles as p
join profiles_with_crew_owner_home_places as q on p.id = q.profile_id
where p.id = 'abc';

When I try this:
const { data, error } = await supabase.from('profiles')
  .select(`
    id, profiles_with_crew_owner_home_places(profile_id)
  `)
  .eq('id', 'abc');
const { data, error } = await supabase.from('profiles')
  .select(`
    id, profiles_with_crew_owner_home_places(profile_id)
  `)
  .eq('id', 'abc');

I get this error: i've added the error in the thread due to character limit.

Which is fine, but basically it is telling me to do something like this:
const { data, error } = await supabase.from('profiles')
  .select(`
    id, profiles_with_crew_owner_home_places!profiles_created_by_profiles_id_fk(profile_id)
  `)
  .eq('id', 'abc');
const { data, error } = await supabase.from('profiles')
  .select(`
    id, profiles_with_crew_owner_home_places!profiles_created_by_profiles_id_fk(profile_id)
  `)
  .eq('id', 'abc');

Which makes the query to work, but it's not what I want, because now it's relating
profiles_with_crew_owner_home_places.profile_id
profiles_with_crew_owner_home_places.profile_id
to
profiles.created_by
profiles.created_by
which is wrong. I need to relate
profiles_with_crew_owner_home_places.profile_id
profiles_with_crew_owner_home_places.profile_id
with
profiles.id
profiles.id
. I've tried it in several ways but nothing works. Please tell me that It has a solution.
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
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Issue querying multi-level/relational tables
SupabaseSSupabase / help-and-questions
3y ago
Querying different schema tables
SupabaseSSupabase / help-and-questions
13mo ago
Querying foreign tables w SDK
SupabaseSSupabase / help-and-questions
4y ago
error while Querying foreign tables - JS
SupabaseSSupabase / help-and-questions
4y ago