title: MYSQL: select latest record only (on left join table)
body: <p>I have 2 tables:  </p>
  
  <blockquote>
    <p>Table1: </p>
  </blockquote>
  
  <pre><code>ID | Mobile Number | Name | Ordered Product| Order Date
  </code></pre>
  
  <p>Table2:</p>
  
  <pre><code>ID(foreign_key can be inserted multipletimes in this table) |Contacted_for | Time(timestamp)
  </code></pre>
  
  <p>I need a query to display all the data in Table1 and if the ID is present in Table 2, I need to display the last inserted record on Table2(with time) of that ID</p>
  
  <p>My query is  </p>
  
  <pre><code>select a.* , b.* FROM table1 a LEFT JOIN table2 b ON a.ID=b.ID GROUP BY a.ID ORDER BY b.Time DESC
  </code></pre>
  
  <p>Here in my query when I remove Group By a.ID, it works but shows all results. But I want to show final record of table2 only(no duplicate ID records)</p>
  
  <p>Thanks in advance</p>