Change legend name according to result from sql query

I am trying to config my legend from result of sql query based on the repeated variable value, give the legend a user-friendly name to show on dashboard. I am trying to use key-value variable, which only show name in selection drop down menu, not able to get the the name. If I config 2 variable, but how could make 2 variable sync with each other, one is id for query, one is name for display?