Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to query using join in Supabase?

Tags:

supabase

In Supabase documentation, it explains this as how you would "join" tables to get data

const { data, error } = await Supabase
  .from('countries')
  .select(`
    name,
    cities (
      name
    )
  `)

But how do I know this works every time when I have not specified which columns would be joined? Is there a way to specify which column to perform join on?

like image 725
dshukertjr Avatar asked Nov 24 '20 23:11

dshukertjr


People also ask

How do you do a join in a queries?

In query Design view, double-click the join you want to change. The Join Properties dialog box appears. In the Join Properties dialog box, note the choices listed beside option 2 and option 3. Click the option that you want to use, and then click OK.

Can you do Joins in Power Query?

To perform an inner joinSelect the Sales query, and then select Merge queries. In the Merge dialog box, under Right table for merge, select Countries. In the Sales table, select the CountryID column. In the Countries table, select the id column.

How do I join a table in Query Builder?

Right-click in the Tables pane, and then click Create Join on the pop-up menu. In the Create Join window, select the source table (first table) and column. Select the target table (second table) and column. Select the join type, and then click OK.

Can we use join in view?

Answers. Yes, you can JOIN views with tables. You can use views just like tables in SELECTs.


1 Answers

So this code works when there is only one relation(foreign key) between the two table countries and cities

const { data, error } = await Supabase
  .from('countries')
  .select(`
    name,
    cities (
      name
    )
  `)

Or when you want to join multiple tables, you can do this:

const { data, error } = await supabase
  .from('products')
  .select(`
    id,
    supplier:supplier_id ( name ),
    purchaser:purchaser_id ( name )
  `)
like image 180
dshukertjr Avatar answered Oct 11 '22 15:10

dshukertjr