title: Mysql how to get related tasks using a relationship table
body: <p>I have three tables:</p>
  
  <p>projects,</p>
  
  <p>project_tasks,</p>
  
  <p>projecttask_projecttask_1_c</p>
  
  <p>I need to select all the tasks related to a project which is easy but the project tasks are separated into milestones and subtasks. The sub tasks are stored in the same table as milestones but have their milestone flag set to 0. The relationship between milestones and sub-tasks is stored in projecttask_projecttask_1_c. So basically I need a query to select milestones and their related subtasks grouped by milestone so it looks like this:  </p>
  
  <pre><code>Milestone
  
    subtask
  
    subtask
  
    subtask
  
  Milestone
  
    subtask
  
    subtask
  </code></pre>
  
  <p>and so on. </p>
  
  <p>We only need the project id from the projects table and I am selecting * from the project_task table. projecttask_projecttask_1_c contains the following fields:</p>
  
  <pre><code>id | date modified | projecttask_projecttask_1projecttask_ida | projecttask_projecttask_1projecttask_idb 
  </code></pre>
  
  <p>where projecttask_projecttask_1projecttask_idb is the id of the milestone task.</p>