title: Display one to many mapping using sql in mybatis
body: <p>I have to tables</p>
  
  <pre><code>Tasks:
   id
   title
   Description
  
  Task_reply_mapping
  task_id
  parent_id
  </code></pre>
  
  <p>I have written the following query to get the data</p>
  
  <pre><code>    select t1.id,t1.title,t1.description,t2.id,t2.title,t2.description
  from tasks t1
  left join Task_reply_mapping trm on t1.id =  trm.task_id 
      left join tasks t2 on t2.id = t1.id
      order by fe.created_at desc limit 0,10
  </code></pre>
  
  <p>This seems to be working fine but its not populating the data correctly. I want to know if this query is correct?</p>
  
  <p>In my mapper file I have </p>
  
  <pre><code>  &lt;resultMap id="TaskResultMap" type="com.mycom.myproj.bean.TaskBean"&gt;
      &lt;id column="id" jdbcType="BIGINT" property="id" /&gt;
      &lt;result column="title" jdbcType="VARCHAR" property="title" /&gt;
      &lt;result column="description" jdbcType="VARCHAR" property="description" /&gt;
    &lt;collection ofType="com.mycom.myproj.bean.TaskBean" property="replyTask"&gt;
      &lt;id column="id" jdbcType="BIGINT" property="id" /&gt;
          &lt;result column="title" jdbcType="VARCHAR" property="title" /&gt;
          &lt;result column="description" jdbcType="VARCHAR" property="description" /&gt;
     &lt;/collection&gt;
    &lt;/resultMap&gt;
  </code></pre>
  
  <p>Or I am doing something wrong in mapper class.</p>
  
  <p>Records in objects are placed like at first index its putting the latest task whether its reply or new task and so on.</p>
  
  <p>It should insert records like this </p>
  
  <pre><code>   Task1
       --1st reply task
       --2nd reply task
    Task 2
        --1st reply task
        --2nd reply task
  </code></pre>
  
  <p>Please let me know if more information is required.</p>