How to get Matlab to join tables when join key is not unique
<p>I have this problem:</p>

<pre><code>table1 = table([1 1 2 2].', [1 2 3 4].');
table2 = table([1 1 2 2].', [100 200 300 400].');
table2.Properties.VariableNames{2} = 'Var3';
join(table1, table2)
</code></pre>

<p>which gives (in 2015b)</p>

<pre><code>&gt;&gt; join(table1, table2)
Error using table/join (line 111)
The key variable for B must have unique values.
</code></pre>

<p>The <code>join</code> command is nice because it preserves original row ordering of <code>table1</code>, however it cannot deal with duplicate key values in <code>table2</code> or missing key values. The commands <code>innerjoin</code> and <code>outerjoin</code> can, but reorder the rows according to the keys.</p>

<p>I would like the new function to behave like SQL so that if there are duplicate values the cross product is used, i.e. the output should be:</p>

<pre><code>ans = 

    Var1    Var2    Var3
    ____    ____    ____

    1       1       100 
    1       2       100 
    1       1       200 
    1       2       200 
    2       3       300 
    2       4       300 
    2       3       400 
    2       4       400 
</code></pre>

<p>and implement this so that the final dataset preserves the original ordering of rows in the first table, followed by the second table. </p>