title: While joining 2 mysql tables how to get only the required related row in second table
body: <p>I have the following <strong>2 tables A and B</strong> in <strong>MySQL</strong> db. When I join the 2 tables by the VisitID (A.VisitID = B.VisitID) I want to pickup only the records that related the <strong>latest Actiondateandtime</strong> from the table B for a VisitID. For example for VisitID = 85 I want to pickup the row with 15/10/2014 3:44 in table B. For VisitID = 86 I only want to pickup the row with 09/10/2014 1:28 in table B.</p>
  
  <p>Table A :</p>
  
  <pre><code>VisitID       VisitTitle                     VisitSummary                        Conclusion
  
  85            Go to Paddy Field 1            Checked Temperatures                1
  86            Soil Quality Checked           Checked PHP of different soil       2
  87            Go to Paddy Field 2            Collected Soil samples              0
  </code></pre>
  
  <p>Table B:</p>
  
  <pre><code>RefID   VisitID      ActionDesc                                 Actiondateandtime
  
  1       85           Submiited to Management                    9/10/2014  12:03
  2       86           Sent to lab                                9/10/2014  1:06
  3       86           Sent to lab                                9/10/2014  1:07
  4       86           Sent to lab                                9/10/2014  1:21
  5       86           Sent to lab                                9/10/2014  1:28
  6       87           Followed with Soil scientist               9/10/2014  1:32
  7       87           Followed with Soil scientist               9/10/2014  1:33
  8       85           Submitted to Management                    15/10/2014 3:44
  </code></pre>
  
  <p>I want the result after the join of these 2 tables</p>
  
  <pre><code>A.VisitID  A.VisitTitle           A.Conclusion  B.RefID   B.VisitID  B.Actiondateandtime
  
  85         Go to Paddy Field 1    1             8         85         15/10/2014 3:44
  86         Soil Quality Checked   2             5         86         9/10/2014 1:28
  87         Go to Paddy Field 2    0             7         87         9/10/2014 1:33
  </code></pre>
  
  <p>What MySQL code needed to get this required result?</p>