title: Select all orders with the specified status saved in another table (PDO)
body: <p>At the moment i have all informations of a order in one table, including the order status.</p>
  <p>In the future i will have a new table &quot;status&quot; to make a order history.</p>
  <p>My tables currently look like this (simplified):</p>
  <p>Table &quot;orders&quot;:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>date</th>
  <th>name</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>10001</td>
  <td>2021-08-24 16:47:52</td>
  <td>Surname Lastname</td>
  </tr>
  <tr>
  <td>10002</td>
  <td>2021-08-30 17:32:05</td>
  <td>Nicename Nicelastname</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Table &quot;status&quot;:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>id</th>
  <th>order_id</th>
  <th>statusdate</th>
  <th>status</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>1</td>
  <td>10001</td>
  <td>2021-08-24 16:47:52</td>
  <td>new</td>
  </tr>
  <tr>
  <td>2</td>
  <td>10002</td>
  <td>2021-08-30 17:32:05</td>
  <td>new</td>
  </tr>
  <tr>
  <td>3</td>
  <td>10001</td>
  <td>2021-08-26 13:44:11</td>
  <td>pending</td>
  </tr>
  <tr>
  <td>4</td>
  <td>10001</td>
  <td>2021-09-02 10:01:12</td>
  <td>shipped</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>My problem is: At this moment i can select all orders with status &quot;shipped&quot; to list them like that:</p>
  <p><code>$sql = $pdo-&gt;prepare(&quot;SELECT * FROM orders WHERE status = ?&quot;);</code></p>
  <p>(? is my status, e.g. &quot;shipped&quot;)</p>
  <p>I know i have to use LEFT JOIN to combine the two tables (correct? or is there a better/easier way?), but i have absolutely no idea how i can select all orders with status X, because the &quot;status&quot; table can have multiple entries per order_id... So the statement must select only the newest entrie!?</p>