Dynamic Display name for plot

I have a Time Series Plot consiting of multiple line graphs.
I want to give every line a different name which I am currently doing with the aliases in my SQL-Select statements.
My problem is, that every graph should have a name depending on a specific, dynamic value in one of my sql tables. I already asked this question on stackoverflow: sql - Alias Name in Postgresql with value from select statement - Stack Overflow but it seems, that I can’t have an alias in the SQL-Statement based on a select statement to another table. I am wondering if there is any functionality to have dynamic graph names for multiple queries dircetly in Grafana?
Thanks in advance for any help.