How to build detail views that are populated from separate queries?

I've looked at many of the Retool templates that show the concept of a master-detail view. They generally seem to load all data into a table and then reference the selectedRow of the table to populate elements on the detail view e.g. PostgreSQL Admin Panel Template

I would like to do something different.

As the selectedRow on the table is changed, I would like to trigger a SQL query that fetches additional information from the database and then render that information in the detail view.

Is this possible and what's the easiest way? I was hoping to somehow simply bind the results to a Key Value component but that component doesn't seem to have any methods for setting the data.

I know I can hook into the Row select changed event on the table and run a JS script from there but I can't see any easy way to bind the results to components.

Should be easy enough to do, 2 queries, 1 table, 1 Key Value
Query1 - fetch list of master data
Table1 with data property set to {{ query1.data }}
Query2 - fetch detail using some clause like where myid = {{table1.selectedRow.data.myid}}
KeyValue1 with data property set to {{query2.data}}

As you change the selected row, query2 should fire and load into your KeyValue

Thanks. I've tried referencing tables in queries as you suggest ( where myid = {{table1.selectedRow.data.myid}}) but with Postgres that doesn't work unless a certain setting that is supposed to protect against sql injection is disabled

See '{{}}' cannot be used when using the DO-END statement in SQL and SQL bind error, 6 parameters but requires 0 - #4 by paul

Does everyone just turn this setting off?

Are you trying to select multiple rows and run/loop through a detail query for all of them?
I'm not sure of your use case, or how a detail view would work with multiple rows.

A single detail select query should work ok, I'm using Postgres and use this pattern all the time and definitely never needed to disable prepared statements.
eg
Query1: select myid, myname from parent_table
Query2: select * from detail_table where myid = {{table1.selectedRow.data.myid}}