
uj, ujf¶
Union join
x uj y uj [x;y]
x ujf y ujf[x;y]
Where x and y are both keyed or both unkeyed tables, returns the union of the columns, filled with nulls where necessary:
- if
xandyhave matching key column/s, then records inyupdate matching records inx - otherwise,
yrecords are inserted.
q)show s:([]a:1 2;b:2 3;c:5 7)
a b c
-----
1 2 5
2 3 7
q)show t:([]a:1 2 3;b:2 3 7;c:10 20 30;d:"ABC")
a b c d
--------
1 2 10 A
2 3 20 B
3 7 30 C
q)s,t / tables do not conform for ,
'mismatch
q)s uj t / simple, so second table is inserted
a b c d
--------
1 2 5
2 3 7
1 2 10 A
2 3 20 B
3 7 30 C
q)(2!s) uj 2!t / keyed, so matching records are updated
a b| c d
---| ----
1 2| 10 A
2 3| 20 B
3 7| 30 C
uj is a multithreaded primitive.
uj generalizes the , Join operator.
??? detail "Changes in V3.0"
The union join of two keyed tables is equivalent to a [left join](lj.md) of the two tables with the catenation of unmatched rows from the second table.
As a result a change in the behavior of `lj` causes a change in the behavior of `uj`:
<div class="peachq-example" markdown="1">
```q
q)show x:([a:1 2]b:`x`y;c:10 20)
a| b c
-| ----
1| x 10
2| y 20
q)show y:([a:1 2]b:``z;c:1 0N)
a| b c
-| ---
1| 1
2| z
q)x uj y / q 3.0
a| b c
-| ---
1| 1
2| z
q)x uj y / q 2.8
a| b c
-| ----
1| x 1
2| z 20
```
<a class="peachq-repl-link" href="../../../repl?code=show+x%3A%28%5Ba%3A1+2%5Db%3A%60x%60y%3Bc%3A10+20%29%0Ashow+y%3A%28%5Ba%3A1+2%5Db%3A%60%60z%3Bc%3A1+0N%29%0Ax+uj+y%09%09%2F+q+3.0%0Ax+uj+y++++++++%2F+q+2.8&title=uj%2C+ujf&example=docs%2Fref%2Fuj.md%3A2" target="_blank" rel="noopener noreferrer" aria-label="Open in REPL (new tab)" title="Open in REPL (new tab)"><svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M8 5v14l11-7z"/></svg></a>
</div>
Since 2017.04.10, the earlier version is available in all V3.5 and later versions as `ujf`.
Q for Mortals §9.9.7 Union Join