Reputation: 787
Join 2 data tables by Keys only for common rows
I would like to join 2 databases by merging selected keys but only keeping the common values.
For example, having the following data tables:
A = table({'a';'a';'b';'b';'c';'c'},...
[1;2;3;4;5;6],...
{'G1';'G2';'G1';'G2';'G1';'G2'},...
'VariableNames',{'ID','Value','Group'})
B = table({'a';'a';'b';'b';'d';'d'},...
[7;8;10;9;11;12],...
{'G1';'G2';'G2';'G1';'G1';'G2'},...
'VariableNames',{'ID','Value','Group'})
I joined the datatables with outerjoin function as follows:
C = outerjoin(A,B, 'Keys', {'ID' 'Group'}, 'MergeKeys', 1)
In the output C, the 'c' and 'd' ID's will still appear with NA' values. I'm looking for an output wich only includes common values (i.e., excluding rows containing 'c' and 'd' ID's)
Upvotes: 0
Views: 1107
Reputation: 5070
You need to use innerjoin function
C = innerjoin(A,B, 'Keys', {'ID' 'Group'})
Upvotes: 2