Merging the data from 2 different tables together

Hi All,

Apologies in advance if this has already been answered, I’ve searched the forums and can’t find anything that aligns to what I’m attempting to do though (even though it seems really trivial on the face of it).

I have a dashboard where the data type has changed at some point so, when I scroll back in time past that point the dashboard stops working.
What I want to achieve is a way of having the results of the 2 separate queries merged so they form one continuous stream of data - there is no chance that there will be a conflicting data point for a given time entry in both instances of the data.

I have this query which works for present-day data:


Query string:
SELECT last("value") FROM "hass_sensor_power_kw" WHERE ("friendly_name" = 'NWCPA47006 All PV Wattage') AND $timeFilter GROUP BY time($__interval) fill(null)

and I have this query which works for old data:


Query string:
SELECT last("value") FROM "hass_power_kw" WHERE ("friendly_name" = 'NWCPA47006 All PV Wattage') AND $timeFilter GROUP BY time($__interval) fill(null)

I simply want them as a single query so that when I scroll back through time, or choose time windows that reference both of the types of data, they are shown using the same entry rather than two separate lines on a graph.

My data source is Influx if that makes any difference, I found this post: https://community.grafana.com/t/how-to-select-multiple-tables/34627 but UNION doesn’t seem to be something I can perform with Influx.

Any help would be greatly appreciated. I hope that there’s a trivial way of doing a SELECT FROM <Multiple Tables> but I don’t seem to be able to find it.

Note: The example above is just for one widget on the dashboard (I picked a simple one) but I have quite a few on this dashboard that need changing.

That’s not possible on the InfluxQL level. UNION is a SQL command, but Influx is not a SQL (InfluxQL is only similar to SQL, I would say small subset of SQL).

You can investigate flux (modern version of query language for InfluxDB version 2+) or Grafana transformations may help.

Thanks @jangaraj
Since posting I also managed to find this StackOverflow entry: aggregate - Influxdb and Grafana combine multiple SELECT - Database Administrators Stack Exchange

Is there any chance I can perform the same type of operation with my queries?

I will be surprised if influxdb subqueries will be working. Anyway you have data, so you can test it.