title: MySQL JOIN the most recent row only?
body: <p>I have a table customer that stores a customer_id, email and reference. There is an additional table customer_data that stores a historical record of the changes made to the customer, i.e. when there's a change made a new row is inserted.</p>
  
  <p>In order to display the customer information in a table, the two tables need to be joined, however only the most recent row from customer_data should be joined to the customer table.</p>
  
  <p>It gets a little more complicated in that the query is paginated, so has a limit and an offset.</p>
  
  <p>How can I do this with MySQL? I think I'm wanting to put a DISTINCT in there somewhere...</p>
  
  <p>The query at the minute is like this-</p>
  
  <pre><code>SELECT *, CONCAT(title,' ',forename,' ',surname) AS name
  FROM customer c
  INNER JOIN customer_data d on c.customer_id=d.customer_id
  WHERE name LIKE '%Smith%' LIMIT 10, 20
  </code></pre>
  
  <p>Additionaly, am I right in thinking I can use CONCAT with LIKE in this way?</p>
  
  <p>(I appreciate that INNER JOIN might be the wrong type of JOIN to use. I actually have no clue what the difference is between the different JOINs. I'm going to look into that now!)</p>