title: How do I consolidate several invoices that at one point were backordered and then fulfilled in mysql
body: <p>For example I have a 1 invoice with 1 that was in stock and 3 that weren't in stock. Later on, the 2 invoices were created for those backordered ones. I want to be able to consolidate all those invoices into one displaying that 3 that were shipped and 1 that is still on backorder.
  mysql table is as follows:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>order_id</th>
  <th>price</th>
  <th>model</th>
  <th>quantity</th>
  <th>previous_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1788</td>
  <td>1,200</td>
  <td>SBS</td>
  <td>-1</td>
  <td>Null //backordered</td>
  </tr>
  <tr>
  <td>1788</td>
  <td>1,200</td>
  <td>SSC</td>
  <td>-1</td>
  <td>Null //backordered</td>
  </tr>
  <tr>
  <td>1788</td>
  <td>1,200</td>
  <td>SAC</td>
  <td>1</td>
  <td>Null</td>
  </tr>
  <tr>
  <td>1788</td>
  <td>1,200</td>
  <td>SBB</td>
  <td>-1</td>
  <td>Null //backordered</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Second invoice</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>order_id</th>
  <th>price</th>
  <th>model</th>
  <th>quantity</th>
  <th>previous_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1811</td>
  <td>1,200</td>
  <td>SBB</td>
  <td>1</td>
  <td>1788</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Third invoice</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>order_id</th>
  <th>price</th>
  <th>model</th>
  <th>quantity</th>
  <th>previous_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1865</td>
  <td>1,200</td>
  <td>SSC</td>
  <td>1</td>
  <td>1788</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>So as you can see previous_id tracks which was the original order for backordered items.</p>
  <p>My mysql code is:</p>
  <p><code>SELECT * FROM order_product where order_id = 1788 or previous_id = 1788</code>
  which displays all 6 rows but I want to be able to see 3 ordered and 1 backorder. Total should be showing 4 rows.</p>
  <p>The final version should look like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>order_id</th>
  <th>price</th>
  <th>model</th>
  <th>quantity</th>
  <th>previous_id</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1788</td>
  <td>1,200</td>
  <td>SBS</td>
  <td>-1</td>
  <td>Null //backordered</td>
  </tr>
  <tr>
  <td>1788</td>
  <td>1,200</td>
  <td>SSC</td>
  <td>1</td>
  <td>Null</td>
  </tr>
  <tr>
  <td>1788</td>
  <td>1,200</td>
  <td>SAC</td>
  <td>1</td>
  <td>1788</td>
  </tr>
  <tr>
  <td>1788</td>
  <td>1,200</td>
  <td>SBB</td>
  <td>1</td>
  <td>1788</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>How do I achieve this?</p>