title: How to FULL OUTER JOIN multiple tables in MySQL
body: <p>I need to <strong><code>FULL OUTER JOIN</code></strong> multiple tables. I know how to <code>FULL OUTER JOIN</code> two tables from <a href="https://stackoverflow.com/questions/4796872/full-outer-join-in-mysql">here</a>. But I have several tables, and I can't apply it over them. How can I achieve it?<br>
  My <strong>SQL</strong> code, below:</p>
  
  <pre><code>INSERT INTO table
  (
    customer_id
   ,g01
   ,g02
   ,g03
   ,has_card
   ,activity
    )
    SELECT sgd.customer_id, sgd.g01,sgd.g02,sgd.g03,sc.value, a.activity
    FROM s_geo_data sgd
    LEFT JOIN s_category sc
    ON sc.customer_id = sgd.customer_id
      UNION
    SELECT sgd.customer_id, sgd.g01,sgd.g02,sgd.g03,sc.value, a.activity
    FROM s_geo_data sgd
    RIGHT JOIN s_category sc
    ON sc.customer_id = sgd.customer_id
  
      UNION
  
    SELECT sgd.customer_id, sgd.g01,sgd.g02,sgd.g03,sc.value, a.activity
    FROM s_geo_data sgd
    LEFT JOIN s_activity a
    ON a.customer_id = sgd.customer_id
      UNION
    SELECT sgd.customer_id, sgd.g01,sgd.g02,sgd.g03,sc.value, a.activity
    FROM s_geo_data sgd
    RIGHT JOIN s_activity a
    ON a.customer_id = sgd.customer_id
  </code></pre>
  
  <p>Also I tried this query:</p>
  
  <pre><code>INSERT INTO reportls.table
  (
    customer_id
   ,g01
   ,g02
   ,g03
   ,has_card
   ,activity
    )
    SELECT sgd.customer_id, sgd.g01,sgd.g02,sgd.g03,sc.value, a.activity
    FROM s_geo_data sgd
    LEFT JOIN s_category sc
    ON sc.customer_id = sgd.customer_id
    LEFT JOIN s_activity a
    ON sc.customer_id = sgd.customer_id
  
      UNION
  
    SELECT sgd.customer_id, sgd.g01,sgd.g02,sgd.g03,sc.value, a.activity
    FROM s_geo_data sgd
    LEFT JOIN s_category sc
    ON sc.customer_id = sgd.customer_id
    RIGHT JOIN s_activity a
    ON a.customer_id = sgd.customer_id
  
      UNION
  
    SELECT sgd.customer_id, sgd.g01,sgd.g02,sgd.g03,sc.value, a.activity
    FROM s_geo_data sgd
    RIGHT JOIN s_category sc
    ON sc.customer_id = sgd.customer_id
    LEFT JOIN s_activity a
    ON a.customer_id = sgd.customer_id
  </code></pre>
  
  <p>Last query executes very long time, I need faster query. </p>