title: MySQL OUTER JOIN to get separate row result from joint tables
body: <p>I tried this query</p>
  
  <pre><code>SELECT invoices.customer_id AS customer_id, invoices.id AS id, invoices.date AS date, due_date, bonus.date AS p_date, invoices.paid_date, total, bonus.amount AS p, invoices.paid, invoices.balance
  FROM (
  (
  SELECT inv.customer_id AS customer_id, inv.id AS id, inv.order_id AS order_id, inv.date AS date, due_date, 
    GROUP_CONCAT( CONCAT( DATE_FORMAT( p.date, '%d/%m/%Y' ) , ' (', p.amount, ')' ) SEPARATOR ', ' ) AS paid_date, 
    total, COALESCE( sum( p.amount ) , 0 ) AS paid, 
    ( total - COALESCE( sum( p.amount ) , 0 ) ) AS balance
  FROM (
  invoices inv
  )
  LEFT JOIN payments p ON p.invoice_id = inv.id
  GROUP BY inv.id
  )invoices
  )
  FULL OUTER JOIN bonus ON bonus.customer_id = invoices.customer_id
  WHERE invoices.customer_id = '4'
  GROUP BY invoices.order_id
  ORDER BY date DESC
  LIMIT 10
  </code></pre>
  
  <p>And getting SQL syntax error but if I try LEFT/RIGHT instead of FULL OUTER JOIN and works with single roe result. </p>
  
  <pre><code>CUSTOMER_ID     ID  DATE    DUE_DATE    P_DATE  PAID_DATE   TOTAL   P   PAID    BALANCE
  4   1   April, 24 2014 09:38:26+0000    April, 30 2014 00:00:00+0000    May, 10 2014 05:02:31+0000  28/04/2014 (10.00), 25/04/2014 (10.00), 25/04/2014 (150.00), 25/04/2014 (390.00)    680     100     560     120
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/qQkxg.png" alt="Getting this result"></p>
  
  <p>Now the problem is I need P_DATE and P as separate row to display bonus. Can you help me to modify my query so that I can get bonus table record P_DATE and P as separate row and other as separate row.</p>
  
  <p><img src="https://i.stack.imgur.com/cOjWN.png" alt="Desired result"></p>
  
  <p><a href="http://sqlfiddle.com/#!2/534eb/5" rel="nofollow noreferrer">SQLFIDDLE LINK</a></p>
  
  <p>Thank you </p>