Using selected rows in a table as constrain in a SQL where clause


my app is rendering some data as table1 with columns name,id,something. The table has multi-row select enabled, so that the user can select all rows that match his/her criteria.

I know want to use all id values of the selected rows in a a follow-up GBQ query to be the constrain in a where clause, like:

select * from new_table where new_id in ({{}})

I cannot figure out a way to get the criteria of the in-statement to be something like "id1","id2","id4).

Can somebody help me?

Hi Patrick,

Here is one way I believe you can do this (haven't tried).

  1. Create a temporary state variable called 'selectedRowIdList'
  2. Add an 'onRowClick' event handler to the table that calls a JS Query
  3. In that JS Query take the id values from the selected rows in the table and add them to the 'selectedRowIdList' variable as an array
  4. In that same JS Query trigger the query to run
  5. Set the 'in' clause value for the query to be ({{ selectedRowIdList.value.toString }}) <-- I believe this will create a comma separated string of the id's for you

Note: if the data type for the id's is a String you may need to format the temporary state variable to have qualified values (e.g. 'id-1', 'id-2', 'id-3')

1 Like

Hi there! We have some examples of how this can be solved here as well:


Thanks a lot. I found the answer in the cheatsheet posted by Tess.

1 Like

Thanks a lot! That works perfectly!!!

1 Like