title: select top one row each based on foreign key
body: <p>How to list the only top latest one row from each   foreign key column.</p>
  
  <p>Eg.
  I have a below child table:</p>
  
  <pre><code>mysql&gt; select tstatus_id,trip_id,trip_title,trip_id from trip_history_status;
  +------------+---------+-------------+ 
  | tstatus_id | trip_id | trip_title  | 
  +------------+---------+-------------+ 
  |         33 |      35 | Jitesh Trip |  
  |         34 |      36 | Test_trip   | 
  |         35 |      36 | Test_trip1  | 
  |         36 |      36 | Test_trip2  |
  |         37 |      36 | Test_trip3  | 
  +------------+---------+-------------+ 
  </code></pre>
  
  <p>where, </p>
  
  <ul>
  <li><code>tstatus_id</code> = primary key(autoincreement) of table <code>trip_history_status</code></li>
  <li><code>trip_id</code>   = foreign key from a parent table <code>tripdetails</code></li>
  </ul>
  
  <p><strong>Expected Output</strong></p>
  
  <pre><code>+------------+-------------+---------+
  | tstatus_id | trip_title  | trip_id |
  +------------+-------------+---------+
  |         33 | Jitesh Trip |      35 |
  |         37 | Test_trip3  |      36 |
  +------------+-------------+---------+
  </code></pre>
  
  <hr>
  
  <p>But I am not able to think how to solve this, i am getting output like this:</p>
  
  <pre><code>mysql&gt; SELECT  tstatus_id,trip_history_status.trip_title,tripdetails.trip_id
      -&gt; FROM (`trip_history_status`)
      -&gt; JOIN `tripdetails` ON `tripdetails`.`trip_id` = `trip_history_status`.`trip_id`
      -&gt; GROUP BY `tripdetails`.`trip_id`
      -&gt; ORDER BY `tstatus_id` Asc;
  +------------+-------------+---------+
  | tstatus_id | trip_title  | trip_id |
  +------------+-------------+---------+
  |         33 | Jitesh Trip |      35 |
  |         34 | Test_trip   |      36 |
  +------------+-------------+---------+ 
  </code></pre>