Display different tables through the drop-down box

Two tables of the same type in the same database, put the data and results in the two tables on the top, set the drop-down box to display the respective test items and test versions of the two tables, and perform the replacement query through the drop-down box.

Hi @sugar
I don’t understand your question. Could you try explaining it differently?

Create the x variable in the native query, set the drop-down box, we can click the option content in the drop-down box to display multiple tables in the same database

@sugar I still don’t understand the question. A Field Filter will only do a lookup in the column defined in the sidebar of the question, but if you add multiple questions to a dashboard and create a filter linked to both questions, then it will show values from both Field Filters in the dropdown.

Can we query two tables in the same database by creating variables in native queries?

@sugar You can query as many tables as you want, but I still don’t understand your question/problem.
I would recommend that you read these:
https://www.metabase.com/blog/sql-template-variables/index.html
https://www.metabase.com/blog/field-filters/index.html
https://www.metabase.com/blog/dashboard-filters/index.html

@flamber I think he’s trying to give the user the option of which table is queried. For example, one table contains this year’s data, another table contains historical data.
@sugar The only way you can do this is to use a view

Select *, 'First Table' as TableChoice
FROM Table1
UNION ALL
Select *, 'Second Table'
 FROM Table2 

The tables will need to be union compatible (alternatively change the * in the view definition).
Sadly, any additional prompts from that table will contain all values from both tables as there’s no option to cascade the prompts.

1 Like