title: Delete from multiple tables
body: <p>So I am trying to delete from multiple tables (in this scenario 6). I tried using INNER JOINS to delete rows from them all in one query, but couldn't get it to work.</p>
  
  <p>Here is my obnoxious work around:</p>
  
  <pre><code>        // Delete course and everything linked to it (topics, badges, dotpoints, questions &amp; answers)   
          $topic = $this-&gt;db-&gt;query("SELECT * FROM course_topics WHERE course_id = ".$row_id);    
          foreach ($topic-&gt;result() as $t)
          {
              $badge = $this-&gt;db-&gt;query("SELECT * FROM course_topic_badges WHERE topic_id = ".$t-&gt;id);    
              foreach ($badge-&gt;result() as $b)
              {
                  $dotpoint = $this-&gt;db-&gt;query("SELECT * FROM course_topic_dotpoints WHERE badge_id = ".$row_id);
                  foreach ($dotpoint-&gt;result() as $d)
                  {
                      $question = $this-&gt;db-&gt;query("SELECT * FROM quiz_questions WHERE dotpoint_id = ".$d-&gt;id);
                      foreach ($question-&gt;result() as $q)
                      {
                          $answer = $this-&gt;db-&gt;query("SELECT * FROM quiz_answers WHERE question_id = ".$q-&gt;id);
                          foreach ($answer as $a)
                          {
                              $this-&gt;db-&gt;query("DELETE FROM quiz_answers WHERE question_id = ".$q-&gt;id);
                          }
                          $this-&gt;db-&gt;query("DELETE FROM quiz_questions WHERE dotpoint_id = ".$d-&gt;id);
                      }
                      $this-&gt;db-&gt;query("DELETE FROM course_topic_dotpoints WHERE badge_id = ".$b-&gt;id);
                  }
                  $query = $this-&gt;db-&gt;query("DELETE FROM course_topic_badges WHERE topic_id = ".$t-&gt;id);
              }
              $query = $this-&gt;db-&gt;query("DELETE FROM course_topics WHERE course_id = ".$row_id);
          }
          $query = $this-&gt;db-&gt;query("DELETE FROM courses WHERE id = ".$row_id);
  </code></pre>
  
  <p>How can I simplify this?</p>