It is possible using unless operator:

item_stock unless item_purchases

Results in a vector consisting of the elements of item_stock for which there are no elements in item_purchases with exactly matching label sets. All matching elements in both vectors are dropped.

Note that the metrics in question do not have 'exactly matching label sets' (name is common but count and in_stock are not). In this case you can use on to set the list of labels to match:

item_stock unless on(name) item_purchases
Answer from anemyte on Stack Overflow
Top answer
1 of 1
1

Best workaround: union with "or"

The closest I've come uses set operations to execute the query as two branches - one for the "inner join" side, and one that's an anti-join that returns only LHS rows that don't match the RHS. This is very verbose if the LHS is a nontrivial expression instead of a simple stand-alone metric, and it's really inefficient too.

(
  important_metric{}
  * on (join_labels)
    group_left(info_label)
    group by (join_labels, info_label) (
      workload_priorities_info{}
    )
)
# if there's no series on the LHS with the same labels as the RHS after ignoring
# the "info_label" label on each side, add the RHS series to the output, otherwise
# output the LHS series.
or ignoring (info_label)
important_metric{}

with inputs

important_metric{join_labels="1"} 100
important_metric{join_labels="2"} 64
important_metric{join_labels="3"} 5

workload_priorities_info{join_labels="1",info_label="highprio"}
workload_priorities_info{join_labels="3",info_label="lowprio"}

this produces

{join_labels="1",info_label="highprio"} 100
{join_labels="2"} 64
{join_labels="3",info_label="lowprio"} 5

Based on Proposal: PromQL arithmetic with default value, or outer join (issue#13625) this is probably the best workaround that is currently possible.

SQL analogues for comparison

The SQL translation of this would be something like

# inner join to find rows with matching info metrics
SELECT
  important_metric.value * workload_priorities_info.value,
  important_metric.join_labels,
  workload_priorities_info.info_label
FROM important_metric
INNER JOIN workload_priorities_info USING (join_labels)
# append two sets of rows
UNION ALL
# find rows that do NOT have any matching info-metric and append them to
# the result set
SELECT important_metric.value,
  important_metric.join_labels,
  NULL
FROM important_metric
LEFT JOIN INNER JOIN workload_priorities_info USING (join_labels)
WHERE workload_priorities_info.info_label IS NULL

where what we want is the equivalent of

SELECT
  important_metric.value * coalesce(workload_priorities_info.value, 1),
  important_metric.join_labels,
  workload_priorities_info.info_label
FROM important_metric
LEFT JOIN workload_priorities_info USING (join_labels)
Discussions

Promql outer join support
Proposal Outer join (especially left join & right join) are very useful. For example: We have one host level CPU alert (CPU > 70%), and we have another spatial aggregation metrics on pool le... More on github.com
🌐 github.com
1
August 7, 2019
Making joins simpler in PromQL
At yesterday's dev summit, and as part of the discussion around prometheus/snmp_exporter#180 , @brian-brazil also suggested making joins easier to write. This issue is to document possible chan... More on github.com
🌐 github.com
18
August 20, 2017
simpler syntax for joins on labels with different names
Background When doing joins, I usually encounter cases where I want to join through a label that has different names on each side. For example, suppose I have: A container_fs_reads_total metric wit... More on github.com
🌐 github.com
8
October 10, 2024
Joining different labels
I think this will be a common case ... to join such labels could be beneficial. I imagine a syntax along the lines of: container_last_seen and on(pod_name=pod) kube_pod_info · Where the names left and right of = refer to the matched on labels of the left and right metrics respectively. I'd hope it to be easy enough to implement in our parser and think it's generally an rather obvious syntax for the semantics. I know that's not a trivial extension to PromQL, so this is ... More on github.com
🌐 github.com
36
November 18, 2016
🌐
GitHub
github.com › prometheus › prometheus › issues › 7649
PromQL: provide more efficient way to "join" metric in query · Issue #7649 · prometheus/prometheus
July 23, 2020 - Proposal Use case. Why is this important? Currently, PromQL provide keyword group_left to join two metrics, for example job:memory_usage_percent{instance_name=~".*"} * on(instance_name) group_right(app) instance_app_relation{app="test.db...
Author: prometheus
🌐
GitHub
github.com › prometheus › prometheus › issues › 5841
Promql outer join support · Issue #5841 · prometheus/prometheus
August 7, 2019 - Promql outer join support#5841 · Copy link · garrettlish · opened · on Aug 7, 2019 · Issue body actions · Outer join (especially left join & right join) are very useful. For example: We have one host level CPU alert (CPU > 70%), and we have another spatial aggregation metrics on pool level (host count in a pool).
Author: prometheus
🌐
Robust Perception
robustperception.io › left-joins-in-promql
Left joins in PromQL – Robust Perception | Prometheus Monitoring Experts
December 30, 2019 - PromQL by default effectively does an inner join and requires that labels (except the metric name) on both sides of the expression to be exactly the same and match one-to-one. There's no way in PromQL to increase your cardinality (other than absent(), which can only go from 0 to 1).
🌐
Yannick Pereira-Reis
ypereirareis.github.io › blog › 2020 › 02 › 21 › how-to-join-prometheus-metrics-by-label-with-promql
How to join Prometheus metrics by label with PromQL – Yannick Pereira-Reis
sum(node_disk_bytes_read * on(instance) group_left(node_name) node_meta{}) by (node_name) on(instance) => this is how to JOIN on label instance.
🌐
GitHub
github.com › prometheus › prometheus › issues › 3094
Making joins simpler in PromQL · Issue #3094 · prometheus/prometheus
August 20, 2017 - At yesterday's dev summit, and as part of the discussion around prometheus/snmp_exporter#180 , @brian-brazil also suggested making joins easier to write. This issue is to document possible chan...
Author: prometheus
🌐
GitHub
github.com › influxdata › flux › blob › master › stdlib › internal › promql › join.md
flux/stdlib/internal/promql/join.md at master · influxdata/flux
left · object · Table stream · right · object · Table stream · fn · function · Defines the function that joins the rows of each table. The return value is an object which defines the output record structure.
Author: influxdata
Find elsewhere
🌐
Iximiuz
iximiuz.com › en › posts › prometheus-vector-matching
Prometheus Cheat Sheet - How to Join Multiple Metrics (Vector Matching)
November 30, 2021 - How to join metrics on matching labels? Vector matching: one-to-one, one-to-many and many-to-one, many-to-many. What on/ignoring clause is for? group_left and group_right explained. Logical/set operations explained.
🌐
GitHub
github.com › prometheus › prometheus › issues › 15146
simpler syntax for joins on labels with different names · Issue #15146 · prometheus/prometheus
October 10, 2024 - When doing joins, I usually encounter cases where I want to join through a label that has different names on each side. For example, suppose I have: A container_fs_reads_total metric with a pod label · A some_custom_pod_info metric with a exported_pod label ... container_fs_reads_total{} * on(pod) group_left label_replace(some_custom_pod_info{}, "pod", "$1", "exported_pod", "(.*)")
Author: prometheus
🌐
GitHub
github.com › prometheus › prometheus › issues › 2204
Joining different labels · Issue #2204 · prometheus/prometheus
November 18, 2016 - I think this will be a common case ... to join such labels could be beneficial. I imagine a syntax along the lines of: container_last_seen and on(pod_name=pod) kube_pod_info · Where the names left and right of = refer to the matched on labels of the left and right metrics respectively. I'd hope it to be easy enough to implement in our parser and think it's generally an rather obvious syntax for the semantics. I know that's not a trivial extension to PromQL, so this is ...
Author: prometheus
🌐
Felixhummel
blag.felixhummel.de › 25 › 08-01-til-prometheus-promql-left-join.html
TIL: Prometheus (PromQL) LEFT JOIN — Felix' Wobsite
August 1, 2025 - SELECT * FROM node_exporter_build_info LEFT OUTER JOIN node_os_info ON a.foo = b.foo AND a.bar = b.bar
🌐
GitHub
github.com › prometheus › prometheus › issues › 13625
Proposal: PromQL arithmetic with default value, or outer join · Issue #13625 · prometheus/prometheus
February 21, 2024 - Proposal If I have data in foo and data in bar, then foo + bar will add them up. If there are some gaps in foo or bar then foo + bar will have gaps in all of those places. I would like to add them and have PromQL treat a missing value as...
Author: prometheus
🌐
Scamcalculate
iai.scamcalculate.pw › promql-join.html
Promql join. SQL | Join (Inner, Left, Right and Full Joins)
Dismiss Join GitHub today GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together. Sign up. Prometheus Query CLI. Go Branch: master. Find file. Sign in Sign up. Go back. Launching Xcode If nothing happens, download Xcode and try again. Latest commit Fetching latest commit…. Promql CLI Query prometheus from the command line for quick analysis.
🌐
Reddit
reddit.com › r › PrometheusMonitoring › comments › ehjyl0 › left_joins_in_promql
r/PrometheusMonitoring - Left joins in PromQL
December 30, 2019 - robustperception.io/left-j... 0 comments · share · save · hide · report · 99% Upvoted · Sort by: best · no comments yet · Be the first to share what you think! r/PrometheusMonitoring · Prometheus Monitoring subreddit · 5.3k · Members · 4 · Online · Created Jul 12, 2015 · Join ·
🌐
GitHub
github.com › influxdata › flux › pull › 1886
docs(promql): group key join for promql by jlapacik · Pull Request #1886 · influxdata/flux
A row on the left will only join with a row on the right if both rows have the same group key value as well as the same _time value. Everything else is discarded. And yes this is what PromQL does. PromQL doesn't support the other types of joins.
Author: influxdata
🌐
Grafana
grafana.com › blog › 2021 › 08 › 04 › how-to-use-promql-joins-for-more-effective-queries-of-prometheus-metrics-at-scale
How to use PromQL joins for more effective queries of Prometheus metrics at scale | Grafana Labs
August 5, 2021 - Run a single rule per metric that uses a PromQL join to inject the appropriate reference label into the generated series. ... groups: - name: slo_metric expr: count(api_response_latency{labelone="xyz", labeltwo="abc"} > 100) labels: reference_label: xyzabc ... This file would be collected by Grafana Agent. Then the following rule group could be used in Cortex: ... groups: - name: slo_metric expr: count by (reference_label) ((api_response_latency * on (labelone,labeltwo) group_left(reference_label) sli_info > 100)
🌐
GitHub
github.com › VictoriaMetrics › VictoriaMetrics › issues › 1827
Query with "group_left" is slow · Issue #1827 · VictoriaMetrics/VictoriaMetrics
November 18, 2021 - Description All my query_range queries with "group_left" are slow, taking more than 10s. Other queries are very quick. Is it normal? For example: with group_left: without group_left: Vers...
Author: VictoriaMetrics