© 2026 Hedgehog Software, LLC

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

Querying foreign tables w SDK

Lower importance question, but wondering if I can get a cleaner implementation. Per https://supabase.com/docs/reference/javascript/select#query-foreign-tables I am able to successfully access data across a join table by doing something like this as an example:

const { data, error } = await supabase.from('countries').select(`
    name,
    country_capitals (
      city (
        name
      )
  `)
const { data, error } = await supabase.from('countries').select(`
    name,
    country_capitals (
      city (
        name
      )
  `)


However, the data returned is:

{ 
  "name": "USA", 
  "country_capitals": [
    {"city": { "name": "Chicago" } },
    {"city": { "name": "New York" } } 
  ] 
}
{ 
  "name": "USA", 
  "country_capitals": [
    {"city": { "name": "Chicago" } },
    {"city": { "name": "New York" } } 
  ] 
}


Is there a way to just return the data directly without the join table nesting? Like:

  "name": "USA",
  "capitals": ["Chicago", "New York"
  "name": "USA",
  "capitals": ["Chicago", "New York"


etc... I know I can do the transformation on the frontend, but seems cleaner if there is just a better way of requesting the data from the SDK
Fetch data: select() | Supabase
Performs vertical filtering with 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

error while Querying foreign tables - JS
SupabaseSSupabase / help-and-questions
4y ago
Querying different schema tables
SupabaseSSupabase / help-and-questions
13mo ago
Issue to query foreign tables
SupabaseSSupabase / help-and-questions
4y ago
Querying Joins and Nested tables issue
SupabaseSSupabase / help-and-questions
3mo ago