Help

Re: API Retrieving records from multiple tables

Solved
Jump to Solution
2450 0
cancel
Showing results for 
Search instead for 
Did you mean: 
Bill_McIntyre
4 - Data Explorer
4 - Data Explorer

Has anyone retrieved data from multiple tables via the api? I can retrieve one set from one table no problem and I know how to to do this in SQL for muliple inner or outer joins but I have a little bit of a block doing this in node.js using the api.

Thank you

1 Solution

Accepted Solutions
Fernando_Amorim
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi @Bill_McIntyre, in order to use the similar to JOINS, you have to link in the main table you are going to select to the other table, using the ‘Link to another record’ column, once you added and linked the record to the main table, you can filter it using the PRIMARY COLUMN column in the other table.

Exp:
‘Main table’, has a link to record column named as ‘Product’, the table ‘Product’, has the primary column as ‘Composed Product Name’, to make it unique, or use and AI column. So, that said, you can select from the table passing the filterByFormula values, something like this:

//in this case i'm using async/await, which doesn't require .then or done
try{
     let records = await base('Main table').select({filterByFormula: "{Product} = \"Myprimarykeyhere\""}).all();
} catch (err) { console.error(err); }

Then you can catch only the row you want, referencing it by “foreign key”. There are other formulas to use if you need and AND, OR, etc. See: https://support.airtable.com/hc/en-us/articles/203255215-Formula-field-reference

See Solution in Thread

3 Replies 3
Fernando_Amorim
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi @Bill_McIntyre, in order to use the similar to JOINS, you have to link in the main table you are going to select to the other table, using the ‘Link to another record’ column, once you added and linked the record to the main table, you can filter it using the PRIMARY COLUMN column in the other table.

Exp:
‘Main table’, has a link to record column named as ‘Product’, the table ‘Product’, has the primary column as ‘Composed Product Name’, to make it unique, or use and AI column. So, that said, you can select from the table passing the filterByFormula values, something like this:

//in this case i'm using async/await, which doesn't require .then or done
try{
     let records = await base('Main table').select({filterByFormula: "{Product} = \"Myprimarykeyhere\""}).all();
} catch (err) { console.error(err); }

Then you can catch only the row you want, referencing it by “foreign key”. There are other formulas to use if you need and AND, OR, etc. See: https://support.airtable.com/hc/en-us/articles/203255215-Formula-field-reference

And for getting fields from the other table, you have to use a Lookup column, to reference the item from the other table and bring it to the ‘Main table’.

Thank you Fernando. I was focusing too much on the node.js code. This is elegant and I will just make a hidden table with all the fields linked from other tables. Spot On!