The Join operator
A * B combines the matching information in
The result contains all matching combinations of tuples from both arguments.
Principles of joins¶
- The operands
Bmust be join-compatible.
- The primary key of the result is the union of the primary keys of the operands.
Examples of joins¶
Example 1 : When the operands have no common attributes, the result is the cross product -- all combinations of tuples.
Example 2 : When the operands have common attributes, only tuples with matching values are kept.
Example 3 : Joining on non-primary attribute
Left joins are not yet implemented: https://github.com/datajoint/datajoint-python/issues/264
A modification of the join operator is the left join. It is implemented as
A ** B in Python and
A .* B in MATLAB.
The left join keeps all the tuples from
A even in the absence of the matching tuples from
B. For tuples with no matches in
B, the non-key attributes from
B are filled with
Example 4 : A left join
Caution: The left join is the only operator that can introduce
NULLs in the primary key of the result.
NULLs in primary attributes may produce unintuitive results in subsequent expressions.
Properties of join¶
Bhave the same attributes, the join
A * Bbecomes equivalent to the set intersection
B. Hence, DataJoint does not need a separate intersection operator.
A * Bis equivalent to
B * A. However, the left join is not commutative.
(A * B) * Cis equivalent to
A * (B * C). However, the left joint is not associative.