Search code examples
supabasesupabase-databasesupabase-js

Supabase JavaScript data fetching with nested select


I am new to supabase and data fetching via supabase-js client.

When I have the tables below and I have to fetch votes and additionally data from the result and club table, how does this work? Respectively is it possible to have nested selects? Unfortunately I could not find an example in https://supabase.com/docs/guides/api/joins-and-nesting or https://supabase.com/docs/reference/javascript/select.

From Prisma I know it can be realized with nested includes as described here. Is this possible in supabase too?

Voting table

id title result_id
1 Voting title 1 1
2 Voting title 2 2

Result table

id yes no club_id
1 300 406 1
2 21 12 2
2 265 201 3

Club table

id name
1 Club A
2 Club B
3 Club C

Solution

  • There is an example for querying nested tables in the docs that you liked right here. https://supabase.com/docs/guides/database/joins-and-nesting

    You can query them like this:

    const {data, error} = await supabase.from('votes').select('*, results(*, clubs(*))')