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?
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.
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.
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.
Answers. Yes, you can JOIN views with tables. You can use views just like tables in SELECTs.
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 )
`)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With