title: MySQLi + PHP sort by date and ID in descending order
body: <p>I'm looking for a MySQL query that will sort the items by date in descending order. If it finds two or more rows with the same date, it will sort them by ID in descending order.</p>
  
  <p>This is my current code:</p>
  
  <pre><code>$sql = "SELECT $rows FROM $table ORDER BY Date DESC";
  </code></pre>
  
  <p>It displays the items in descending order by date but if there are two items with the same date, it displays them in ascending order by ID instead of descending.</p>
  
  <p>Example:</p>
  
  <p>Let's assume that this is a set of data:</p>
  
  <pre><code>ID - date       - text
  1  - 2017-01-01 - oldest
  2  - 2017-01-02 - two
  3  - 2017-01-03 - morning
  4  - 2017-01-03 - afternoon
  5  - 2017-01-04 - latest
  </code></pre>
  
  <p>The current code would list it as:</p>
  
  <pre><code>ID - date       - text
  5  - 2017-01-04 - latest
  3  - 2017-01-03 - morning
  4  - 2017-01-03 - afternoon
  2  - 2017-01-02 - two
  1  - 2017-01-01 - oldest
  </code></pre>
  
  <p>I want it to list it as this:</p>
  
  <pre><code>ID - date       - text
  5  - 2017-01-04 - latest
  4  - 2017-01-03 - afternoon
  3  - 2017-01-03 - morning
  2  - 2017-01-02 - two
  1  - 2017-01-01 - oldest
  </code></pre>
  
  <p>I don't want to simply sort by ID because sometimes I want to add events that happened in the past and this would require me to manually edit the ID of all events after that one.</p>
  
  <p>Sorting simply by date does not consider two events that happen on the same day at different times. The one with a higher ID is almost always going to be the one that happened last.</p>
  
  <p>I could sort by time and date potentially but I do not have any time data on past events and I want to keep it consistent.</p>