title: How can I get nested results from a MySQL table AND link to another table?
body: <p>I have a table of comments:</p>
  
  <hr>
  
  <p>comment_id  int(11)         No      auto_increment<br>
  profile_id  int(11)         No<br>
  type    char(1) latin1_swedish_ci       No<br>
  parent_id   int(11)         No<br>
  text    mediumtext  latin1_swedish_ci       No<br>
  datetime    datetime            No<br>
  vote_score  int(11)</p>
  
  <hr>
  
  <p>Where "type" can be "a", a comment on an article, or "c", a comment on a comment (a reply)</p>
  
  <p>"parent_id" says whether the comment is a child of article_id=1 or comment_id=1</p>
  
  <p>It's linked to table "profiles" where comments.profile_id=profile.profile_id (so i can get profile.first_name, for example)</p>
  
  <hr>
  
  <p>THE CHALLENGE:</p>
  
  <p>I'd like to get a SQL query that gives me the comments in order as they'd be displayed:</p>
  
  <blockquote>
    <p>comment 1 [type=a]</p>
    
    <blockquote>
      <p>(reply to comment 1) [type=c]</p>
      
      <p>(reply to comment 2)  [type=c]</p>
    </blockquote>
    
    <p>comment 2 [type=a]</p>
  </blockquote>
  
  <p>What SQL query do I need to do this? (The objective is to return the results in correct order so I can have a SIMPLE php WHILE loop print the results.)</p>
  
  <p>Thanks!</p>