Flux querry as input for mysql?

Within grafana I have a large’ish number of devices reporting telemetry. We also have a mysql database with other non-telemetry but interesting information for the same - and a lot more - devices. What I would like to do is to get for example the serial number from a device using flux, then use that as a variable into a mysql query to for example loop up install address.

Currently I have found a way to make a static mysql query for all devices with serial on expected format, then do a join. So I know the connectivity works. I know I can combine the data into a useful output. But the mysql query does not scale for production if I have to list out the database all the time.

Any way to use flux output to build a sql querry?