0

I have some tables on supabase db.
There is a post table and it contains user_id from profiles table.
user_id field related with the id of profiles table.
I am using @supabase node module for pulling data from supabase.
I can pull data with single query, but I don't know the way of pulling data from multiple tables with a query.
I followed this answer, but it doesn't help me. The response's result doesn't contain the profile information.
Here is the code I tried to use.

await supabase
  .from('posts')
  .select(`user_id,
    profiles(
      first_name
    )
  `);

How can I solve this problem?

Cardoso
  • 962
  • 1
  • 12
  • 30
  • 1
    Does this answer your question? [How to query using join in Supabase?](https://stackoverflow.com/questions/64996432/how-to-query-using-join-in-supabase) – Thomas Sablik Feb 24 '23 at 03:10

1 Answers1

0

Assuming you have a foreign key relationship between your user_id column and the profiles table, the following will return you the posts data as well as the profiles data of user_id on each posts row.

const { data, error } = await supabase
  .from('posts')
  .select(`*,
    profiles(
      first_name
    )
  `);

If this does not work, you probably do not have a foreign key relationship between the user_id column and profiles table. You can read the official guide on how to add foreign key relationship. https://supabase.com/docs/guides/database/tables#joining-tables-with-foreign-keys

dshukertjr
  • 15,244
  • 11
  • 57
  • 94