last_updated: 2025-08-01

TIL: Prometheus (PromQL) LEFT JOIN#

Note that Prometheus matches on labels. The following query will only show instance, because that’s the only label that matches both series.

group by (instance, version) (node_exporter_build_info)
* on (instance) node_os_info

LEFT JOIN#

SELECT *
FROM node_exporter_build_info
LEFT JOIN node_os_info ON a.foo = b.foo AND a.bar = b.bar
group by (instance, version) (node_exporter_build_info)
* on (instance) group_left(name, version_codename, version_id) node_os_info

This reduces rows to those matching labels in node_os_info.

LEFT OUTER JOIN#

SELECT *
FROM node_exporter_build_info
LEFT OUTER JOIN node_os_info ON a.foo = b.foo AND a.bar = b.bar
group by (instance, version) (node_exporter_build_info)
* on (instance) group_left(name, version_codename, version_id) node_os_info
or on (instance) node_exporter_build_info

This returns all rows from both node_exporter_build_info and node_os_info.