%% Merge Tables with One Variable in Common
% Create a table, Tleft.

Tleft = table([5;12;23;2;6],...
        {'cereal';'pizza';'salmon';'cookies';'pizza'},...
        'VariableNames',{'Age','FavoriteFood'},...
        'RowNames',{'Amy','Bobby','Holly','Harry','Sally'})

%
% Create a table, Tright, with one variable in common with Tleft.

Tright = table({'cereal';'cookies';'pizza';'salmon';'cake'},...
         [110;160;140;367;243],...
         {'B';'D';'B-';'A';'C-'},...
         'VariableNames',{'FavoriteFood','Calories','NutritionGrade'})

%
% Create a new table, T, with data from tables Tleft and Tright. The variable in common, FavoriteFood, is used as a key variable by the join function.

T = join(Tleft,Tright)

% Table T does not include information from the last row of table Tright about 'cake' because there is no corresponding entry in table Tleft.
% Copyright 2012 The MathWorks, Inc.