Note that there are some explanatory texts on larger screens.

plurals
  1. POJoining many tables on same data and returning all rows
    primarykey
    data
    text
    <h2>UPDATE:</h2> <p>my orgional attempt to use FULL OUTER JOIN did not work correctly. I have updated the question to reflex the true issue. Sorry for presenting a classic <a href="http://www.perlmonks.org/index.pl?node_id=542341" rel="nofollow">XY PROBLEM</a>.</p> <hr> <p>I'm trying to retrieve a dataset from multiple tables all in one query thats is grouped by year, month of the data.</p> <p>The final result should look like this:</p> <pre> | Year | Month | Col1 | Col2 | Col3 | |------+-------+------+------+------| | 2012 | 11 | 231 | - | - | | 2012 | 12 | 534 | 12 | 13 | | 2013 | 1 | - | 22 | 14 | </pre> <p>Coming from data that looks like this:</p> <p><strong>Table 1:</strong></p> <pre> | Year | Month | Data | |------+-------+------| | 2012 | 11 | 231 | | 2012 | 12 | 534 | </pre> <p><strong>Table 2:</strong></p> <pre> | Year | Month | Data | |------+-------+------| | 2012 | 12 | 12 | | 2013 | 1 | 22 | </pre> <p><strong>Table 3:</strong></p> <pre> | Year | Month | Data | |------+-------+------| | 2012 | 12 | 13 | | 2013 | 1 | 14 | </pre> <p>I tried using <code>FULL OUTER JOIN</code> but this doesn't quite work because in my <code>SELECT</code> clause because no matter which table I select 'Year' and 'Month' from there are null values.</p> <pre><code>SELECT Collase(t1.year,t2.year,t3.year) ,Collese(t1.month,t2.month,t3.month) ,t1.data as col1 ,t2.data as col2 ,t3.data as col3 From t1 FULL OUTER JOIN t2 on t1.year = t2.year and t1.month = t2.month FULL OUTER JOIN t3 on t1.year = t3.year and t1.month = t3.month </code></pre> <p>Result is something like this (is too confusing to repeat exactly what i would get using this demo data):</p> <pre> | Year | Month | Col1 | Col2 | Col3 | |------+-------+------+------+------| | 2012 | 11 | 231 | - | - | | 2012 | 12 | 534 | 12 | 13 | | 2013 | 1 | - | 22 | | | - | 1 | - | - | 14 | </pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload