innerjoin

Joins two tables keeping only the rows whose key appears in both.

Category: Language Fundamentals > Data Types

Syntax

C = innerjoin(A, B)

Joins on the variables the two tables have in common.

C = innerjoin(A, B, 'Keys', k)

Joins on the named key variable(s).

Description

A row appears in the result only when its key is present in both tables. If a key repeats, every pairing of the matching rows is produced. Keys that occur in only one table are dropped; use outerjoin to keep them.

Input arguments

A, B
Tables.
'Keys'
Name or names of the key variables present in both tables.

Output arguments

C
Table with the key variables, then the remaining variables of A, then those of B.

Example

Matching keys

A = table([1; 2; 3], {'a'; 'b'; 'c'}, 'VariableNames', {'k', 'x'});
B = table([1; 3; 4], [10; 30; 40], 'VariableNames', {'k', 'y'});
innerjoin(A, B, 'Keys', 'k')
Output
ans = 2×3 table

    k      x      y 
    _    _____    __

    1    {'a'}    10
    3    {'c'}    30

See also

outerjoin join table union intersect