© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
SupabaseS
Supabase•3y ago•
2 replies
garyditsch

Filtering referenced tables

I see this example in the docs:

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

    name,
    cities!inner (
      name
    )
  

    name,
    cities!inner (
      name
    )
  
)
.eq('cities.name', 'Bali')

My example here is not returning what I expect, which would be 4 rows from the behaviors table where the goal.id match

const { data, error } = await supabase
.from('behaviors')
.select(

      id, goal_id, created_at, user_id,
      goals (
        id, goal, value, category 
      )
    

      id, goal_id, created_at, user_id,
      goals (
        id, goal, value, category 
      )
    
)
.eq('goals.id', 6)

I am getting back all behavior objects and where goals.id = 6, the goals object is there. In the behavior objects that goals.id != 6, I just get a "goals: null" ... I guess my expectation is that I would only get back the objects where goals.id was six and the other objects are filtered out.

Similar to the output of this:

const { data, error } = await supabase
.from('behaviors')
.select(

      id, goal_id, created_at, user_id,
      goals (
        id, goal, value, category 
      )
    

      id, goal_id, created_at, user_id,
      goals (
        id, goal, value, category 
      )
    
)
.eq('goal_id', 6)

However, I'd prefer to filter on the goals.category value, so confused on how to properly filter off the referenced table.
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

RLS Query referenced tables
SupabaseSSupabase / help-and-questions
3y ago
Tables In Tables?
SupabaseSSupabase / help-and-questions
4y ago
Autofill UID in the referenced column.
SupabaseSSupabase / help-and-questions
4y ago
Lost tables
SupabaseSSupabase / help-and-questions
4mo ago