lj, ljf¶
Left join
x lj y lj [x;y]
x ljf y ljf[x;y]
Where
xis a table, or the name of a table as a symbol, in which caseljupdates the table in placeyis- a keyed table whose key columns are columns of
x, returnsxandyjoined on the key columns ofy - or (for
ljonly) the general empty list(), returnsx
- a keyed table whose key columns are columns of
For each record in x, the result has one record with the columns of y joined to the columns of x:
- If there is a matching record in
y, it is joined to thexrecord, and common columns take their values fromy. - If there is no matching record in
y, common columns are unchanged and new columns are null.
If y has duplicate keys, lj uses the first matching record.
q)show x:([]a:1 2 3;b:`I`J`K;c:10 20 30)
a b c
------
1 I 10
2 J 20
3 K 30
q)show y:([a:1 3;b:`I`K]c:1 2;d:10 20)
a b| c d
---| ----
1 I| 1 10
3 K| 2 20
q)x lj y
a b c d
---------
1 I 1 10
2 J 20
3 K 2 20
This expression returns the y columns that lj joins to x:
q)y[select a,b from x]
c d
----
1 10
2 20
lj signals a type error if y is not a keyed table.
q)x lj 0!y
'type
[0] x lj 0!y
^
lj is a cover for ,\: (Join Each Left) that also accepts a keyed table as x.
lj is a multithreaded primitive.
ljf¶
With lj, a null in a matching record of y overwrites the value in x.
ljf instead fills from x where the value in y is null.
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 lj y
a b c
-----
1 1
2 z
q)x ljf y
a b c
------
1 x 1
2 z 20
Q for Mortals §9.9.2 Ad Hoc Left Join