Populate Custom Column with database query

Hi!

I've a table table2 with a column A that is the result of an API call. Now, I want to add a custom column A_name and populate it with the result of the following query (query 4):

SELECT A_name FROM myTable WHERE A = {{table2.selectedRow.data.A}}

using {{query4.data.A_name}} as the display value.

But, of course, this way all the rows stay with the A_name of the selected row:

Is there a simple way to populate this table correctly? I've tried to adapt the code from Scripting Retool but without success.

Thank you!

Hi @Gui, I think there are multiple ways of approaching this, but I think making a query for every row in your current table can lead to a lot of queries being run when you start scaling and having more rows. My suggestion is to query myTable once doing SELECT A_name FROM myTable WHERE A = any ({{my_array_of_A.value}}).

You can then plug the data into your table with a custom column and matching the row by using the index [i]. An example of this would look like this for the custom_column's value: {{ query2.data.A_name[i] }}.

Here's an attached demo app to help demonstrate, hope this helps!
custom-20columns-20with-20second-20query.json