<commit_before>---
title: How to join data with Flux
description: This guide walks through joining data with Flux and outlines how it shapes your data in the process.
menu:
  flux_0_7:
    name: Join data
    parent: Guides
    weight: 2
---

The [`join()` function](/flux/v.07/functions/transformations/join) merges two or more
input streams whose values are equal on a set of common columns into a single output stream.
Flux allows you to join on any columns common between two data streams and opens the door
for operations such as cross-measurement joins and math across measurements.

To illustrate a join operation, use data captured by Telegraf and and stored in
InfluxDB with a default TICK stack installation - memory usage and processes.

> If using the [InfluxData Sandbox](/platform/installation/platform-install) or other
> "Dockerized" instances of the TICK stack, these measurements may not be available.

In this guide, we'll join two data streams, one representing memory usage and the other representing the
total number of running process, then calculate the average memory usage per running process.

## Define stream variables
In order to perform a join, you must have two streams of data.
Assign a variable to each data stream.

### Memory used variable
Define a `memUsed` variable that filters on the `mem` measurement and the `used` field.
This returns the amount of memory (in bytes) used.

###### memUsed stream definition
```js
memUsed = from(bucket: "telegraf/autogen")
  |> range(start: -5m)
  |> filter(fn: (r) =>
    r._measurement == "mem" AND
    r._field == "used"
  )
```

{{% condense %}}
###### memUsed data output
```
Table: keys: [_start, _stop, _field, _measurement, host]<commit_msg>fixed typo in join guide<commit_after>---
title: How to join data with Flux
description: This guide walks through joining data with Flux and outlines how it shapes your data in the process.
menu:
  flux_0_7:
    name: Join data
    parent: Guides
    weight: 2
---

The [`join()` function](/flux/v.07/functions/transformations/join) merges two or more
input streams whose values are equal on a set of common columns into a single output stream.
Flux allows you to join on any columns common between two data streams and opens the door
for operations such as cross-measurement joins and math across measurements.

To illustrate a join operation, use data captured by Telegraf and and stored in
InfluxDB with a default TICK stack installation - memory usage and processes.

> If using the [InfluxData Sandbox](/platform/installation/platform-install) or other
> "Dockerized" instances of the TICK stack, these measurements may not be available.

In this guide, we'll join two data streams, one representing memory usage and the other representing the
total number of running processes, then calculate the average memory usage per running process.

## Define stream variables
In order to perform a join, you must have two streams of data.
Assign a variable to each data stream.

### Memory used variable
Define a `memUsed` variable that filters on the `mem` measurement and the `used` field.
This returns the amount of memory (in bytes) used.

###### memUsed stream definition
```js
memUsed = from(bucket: "telegraf/autogen")
  |> range(start: -5m)
  |> filter(fn: (r) =>
    r._measurement == "mem" AND
    r._field == "used"
  )
```

{{% condense %}}
###### memUsed data output
```
Table: keys: [_start, _stop, _field, _measurement, host]
{'fraction_non_alphanumeric': 0.08147934123085813, 'fraction_numerical': 0.0034672060098237503, 'mean_word_length': 4.301684532924962, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6517677', 'n_tokens_mistral': 953, 'n_tokens_neox': 914, 'n_words': 479}