1

I have an SQL table with columns: name and user type.


Name type
John student
Tom teacher
Peter teacher
Steve student

I want to have a grafana variable where I can select a user "type" and the variable passes the value of all the "names" corresponding to that "type" to the dashboard.

I found this example - https://grafana.com/blog/2019/07/17/ask-us-anything-how-to-alias-dashboard-variables-in-grafana-in-sql/ which lets me alias a one to one mapping, but I am looking for a one to many mapping.

Shobhit Kumar
  • 626
  • 1
  • 5
  • 21

2 Answers2

0

You should do it in two steps:

First, per your example create variable, that will contain types.

Than, in the same way create variable, that will contain names, and will use firs variable as parameter for select.

markalex
  • 8,623
  • 2
  • 7
  • 32
0

For this you need to create 2 variables and link them in next order:

  1. Create variable "type", "select distinct type from my_table"
  2. Create variable "Name", "select distinct name from my_table where type = $type", where $type is already your variable from grafana.
КЕМ
  • 1
  • 2