Run query for each row in table retool

I have this table:

I want to display query result inside column 'Total Sent'. How to do that?

This is my query:
SELECT COUNT( AS leeds_count_sent, webservice_resp.id_campanya FROM usuarios_leedia JOIN webservice_resp ON = webservice_resp.id_usuario WHERE webservice_resp.estado_ok = 1 AND webservice_resp.id_campanya = {{ campanya_id }}

I want to replace {{ campanya_id }} with currentRow from the table.

Are you calculating Total sent from the data in the column? OR, are you only able to get the Total Sent value by using each ID listed in the table?

@ScottR I want to get Total Sent value using each ID listed in the table.

So I want my query run in each row like this:
ID 20 = ...WHERE webservice_resp.id_campanya = 20
ID 206 = ... WHERE webservice_resp.id_campanya = 206

And then display each of them in corresponding row of TotalSent column.

Can you simply do a join on the original query getting the data using a with clause....or does that data live somewhere else in another db?

Hey @yeftanma! Just to make sure I’m following 100% - were you able to write all the logic into a single query? Do you need help writing the query? If so, more visibility into the tables you are joining would help! Also, if you’ve already tried rewriting it after ScottR’s suggestion, feel free to post the new query and we can go from there!

Otherwise, if you wanted 2 separate queries, here is a helpful doc to check out. Two helpful callouts would be to:

  1. Change query1 to your query name
  2. Change rows (to get an array of all the IDs)

Hopefully this helps!