join
Combine two tables or timetables by rows using key variables
Description
combines the tables or timetables T = join(Tleft,Tright)Tleft and
Tright by merging rows from the two inputs. The
join function performs a simple form of the join operation
where each row of Tleft must match exactly one row in
Tright. Rows match where the corresponding values in the
key variables are the
same. The output combines all rows from Tleft with the rows from
Tright where the key variables have matching values.
For example, if Tleft has variables named
Key1 and Var1, and
Tright has variables Key1 and
Var2, then T=join(Tleft,Tright) uses
Key1 as a key variable.

By default, the key variables are:
Variables that have the same names in
TleftandTright, if both inputs are tables, or ifTleftis a timetable andTrightis a table.Vectors of row times, if both
TleftandTrightare timetables.
The matching values of the key variables do not have to be in the same orders in
the left and right inputs. Also, the key variables of Tright must
contain all values in the key variables of Tleft. Each value must
occur only once in the key variables of Tright, but can occur
multiple times in the key variables of Tleft. Therefore, the join
operation replicates any row from Tright that matches multiple
rows from Tleft.
The inputs can be tables, timetables, or one of each.
If
Tleftis a table, thenjoinreturnsTas a table.If
Tleftis a timetable, thenjoinreturnsTas a timetable.
specifies options using one or more name-value arguments in addition to the input
arguments in the previous syntax. For example, you can specify which variables to
use as key variables by setting T = join(Tleft,Tright,Name=Value)Keys,
LeftKeys, or RightKeys.
Examples
Input Arguments
Name-Value Arguments
Output Arguments
More About
Algorithms
The join function first finds one or more key variables. Then,
join uses the key variables to find the row in input table
Tright that matches each row in input table
Tleft, and combines those rows to create a row in output table
T.
If there is a one-to-one mapping between key values in
TleftandTright, thenjoinsorts the data inTrightand appends it to tableTleft.If there is a many-to-one mapping between key values in
TleftandTright, thenjoinsorts and repeats the data inTrightbefore appending it to tableTleft.If there is data in a key variable of
Trightthat does not map to a key value inTleft, thenjoindoes not include that data in the output table,T.
Extended Capabilities
Version History
Introduced in R2013b