> For the complete documentation index, see [llms.txt](https://docs.datajet-app.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.datajet-app.com/liquid/filters/right_join.md).

# right\_join

Joins two arrays based on matching keys, similar to SQL RIGHT JOIN. All items from the second array are kept, with matching properties merged from the first array. Non-matching items get `null` values for the first array's properties.

```liquid
{% json employees %}
  [
    { "id": 1, "name": "Ann", "department_id": 10 },
    { "id": 2, "name": "Adam", "department_id": 20 }
  ]
{% endjson %}

{% json departments %}
  [
    { "dept_id": 10, "dept_name": "Accounting", "floor": 3 },
    { "dept_id": 20, "dept_name": "Sales", "floor": 5 },
    { "dept_id": 30, "dept_name": "Marketing", "floor": 7 }
  ]
{% endjson %}

{% assign result = employees | right_join: departments, "department_id = dept_id" %}
{% log result %}
```

Results in following output:

```json
[
  {
    "dept_id": 10,
    "dept_name": "Accounting",
    "floor": 3,
    "id": 1,
    "name": "Ann",
    "department_id": 10
  },
  {
    "dept_id": 20,
    "dept_name": "Sales",
    "floor": 5,
    "id": 2,
    "name": "Adam",
    "department_id": 20
  },
  {
    "dept_id": 30,
    "dept_name": "Marketing",
    "floor": 7,
    "id": null,
    "name": null
  }
]
```

#### Syntax

```liquid
{{ array1 | right_join: array2, "key1 = key2" }}
```

| Parameter | Description                      |
| --------- | -------------------------------- |
| `array1`  | Array to join from               |
| `array2`  | Primary array (all items kept)   |
| `key1`    | Property name in array1 to match |
| `key2`    | Property name in array2 to match |

#### Notes

* Modifies `array2` in place
* Unmatched items receive `null` for properties from `array1` (excluding the join key)
* See also: `left_join` for keeping all items from the first array instead
