I think what you’d like to do is possible. Though from your question it’s not clear to me what it is exactly that’s causing you issues?
I assume that by variable1 and variable2 you mean column1 and column2. To do this you could create a template variable ($variable), which is based on a query like Select t.column1 from table t
that returns all possible values contained in column1.
Then create a panel and set it to repeat for all values of $variable. Within that panel you can have a query like
Select t.column2 from table t where t.column1 = '$variable'
to get all values from column2 that correspond to the respective value of column1 used in that panel. By the way, it’s often useful to check out the query inspector if you’re seeing unexpected behavior.
To some of your other points:
Not sure where this query is actually being used? If it’s within a panel, then assuming that panel repetition has been properly set up (Variable syntax | Grafana documentation), $variable should just have a single value, rather than multiple values. Note that the value that $variable expands to in the query will in the general case be just the “bare” value, so you may need to enclose it in quotation marks for the above query to work.
If you want to use the above outside of a repeating panel, then in the template variable settings, when you enable the All option you can also set a custom all value (in the text box that appears). My SQL is rusty, but I believe you could set this to whatever wildcard value your SQL server recognizes, and use a LIKE
operator instead of =
in your query.
Is that not more or less the objective (though potentially with column1 and column2 reversed - at least based on the requirements you describe)? If the lack of order is an issue, you can of course address that by adding an ORDER
operator to your query.
Hope that helps.