title: How do I select the last child row of a parent/child relationship using SQL
body: <p>Using SQL (MySQL) only I would like to select each of the last child rows of a parent child relationship where the child rows are ordered by a timestamp.    </p>
  
  <p>For example using the tables <code>invoices</code> and <code>invoice_items</code>, I want the newest (ie: most recently timestamped) <code>invoice_items</code> records for each <code>invoice</code> respectively.</p>
  
  <pre><code>--------------------------
  |Invoices                |
  --------------------------
  |invoice_id| other fields|
  --------------------------
  | 1        | ...         |
  --------------------------
  | 2        | ...         |
  --------------------------
  | 3        | ...         |
  --------------------------
  
  --------------------------------------------
  |Invoice_Items                             |
  --------------------------------------------
  | id | invoice_id | invoice_item_timestamp |
  --------------------------------------------
  | 1  | 1            | 2009-12-01 10:00:00  |
  --------------------------------------------
  | 2  | 1            | 2009-12-01 10:01:00  |
  --------------------------------------------
  | 3  | 1            | 2009-12-01 10:02:00  |
  --------------------------------------------
  | 4  | 2            | 2009-12-01 9:00:00   |
  --------------------------------------------
  | 5  | 3            | 2009-12-02 08:30:00  |
  --------------------------------------------
  | 6  | 3            | 2009-12-03 08:31:00  |
  --------------------------------------------    
  </code></pre>
  
  <p>What is the best SQL syntax to produce a resultset that would look something like the following table?</p>
  
  <pre><code>-----------------------------------------------------
  |invoice_id| invoice_item_id |invoice_item_timestamp|
  ---------------------------------------------------
  | 1        | 3               | 2009-12-01 10:02:00  |
  | 2        | 4               | 2009-12-01 09:00:00  |
  | 3        | 6               | 2009-12-03 08:31:00  |
  -----------------------------------------------------
  </code></pre>