MATLAB: What is the difference between inner join and join MATLAB I have two tables, A and B. They are almost identical but in different sorted by rows. I would like to tie them up by rows. Should I use innerjoin or join? What is the difference between inner join and join? Thanks for any help. Best Answer For a join both tables requires the same variables. For an innerjoin the overlapping variables are chosen.A look into the documentation is useful:help joinhelp innerjoinYou can create an innerjoin of:a = table({'a' 'b' 'c' 'e' 'h'}', [1 2 3 11 17]', 'VariableNames',{'Key1' 'Var1'})b = table({'a' 'b' 'd' 'e'}', [4 5 6 7]', 'VariableNames',{'Key1' 'Var2'})The result contains the overlapping keys 'a', 'b', 'e' only. You cannot join them due to the not matching 'c' and 'h'. But you can join:a = table({'a' 'b' 'c' 'e' 'h'}', [1 2 3 11 17]', 'VariableNames', {'Key1' 'Var1'})b = table({'a' 'b' 'h' 'e' 'c'}', [4 5 6 7 8]', 'VariableNames', {'Key1' 'Var2'})Here the join and innerjoin give the same results, so it does not matter, which one you run.Note:join: both tables need the same keysinnerjoin: The result contains the overlapping keys onlyouterjoin: The result contains all keys of both tables and fills missing values with dummies. Related SolutionsMATLAB: Tables: Left Outer Join without changing key names Tell outerjoin to merge the keys.c = outerjoin(a,b,'Type','left','MergeKeys',true); MATLAB: Inner join two tables treating NaN entries as identical Replace the NaNs with "inf", join the tables, then replace the inf with Nan. % Change NaNs to InfsA.Key2(isnan(A.Key2)) = inf;B.Key2(isnan(B.Key2)) = inf;AB = innerjoin(A,B);% Replace Inf with nanAB.Key2(isinf(AB.Key2)) = nan;ResultAB = 4×4 table Key1 Key2 Var1 Var2 ____ ____ ____ ____ 'a' 123 4 1 'b' 456 5 2 'd' 789 6 3 'e' NaN 7 4 Related QuestionOuterjoin tables with identical variable names and unique/non-unique keysJoin two tables with the same headersJoin tables by categorical variableCells merging in tableJoining 2 tables to make 1 tableJoin two tables using outer or inner join
Best Answer