title: MySQL - Select last record from second table matching with first table
body: <p>I have two tables customers and orders, below is the structure.</p>
  
  <p><strong>Table - customers</strong></p>
  
  <ul>
  <li>id</li>
  <li>customer_name</li>
  </ul>
  
  <p><strong>Table - orders</strong></p>
  
  <ul>
  <li>id</li>
  <li>order_id</li>
  <li>customer_id</li>
  </ul>
  
  <p>customers table have customers records and orders table have orders placed by customers, </p>
  
  <p><strong>customer_id</strong> in orders table is linked to the <strong>id</strong> field of customers table.</p>
  
  <p>Now one customer can have zero or one or more than one orders, i want to get the last order placed by customers only.</p>
  
  <p>when i run the following query a simple invisible join, it returns all the orders by the customer</p>
  
  <pre><code>SELECT customers.customer_name,orders.order_id FROM orders,customers WHERE orders.customer_id=customers.id
  </code></pre>
  
  <p>I have also tried different JOIN statements but cannot get the last order by the customer, i want to get it in one SQL query for all customers.</p>
  
  <p>Thank you in advance for your help.</p>