title: MySQL: group by and IF statement
body: <p>By default, <code>parent_id</code> = 0. I want to select all records with <code>parent_id</code> = 0 and only the last ones with <code>parent_id</code> > 0.</p>
  
  <p>I tried this, but it didn't work:</p>
  
  <pre><code>SELECT * FROM `articles`
    IF `parent_id` &gt; 0 THEN
  GROUP BY `parent_id`
  HAVING COUNT(`parent_id`) &gt;= 1
  END;
  ORDER BY `time` DESC
  </code></pre>
  
  <p>I mean, that if there are a few records with parent_id = 2, only one of them should be return. Also, if there a number of records with parent_id = 5, only one of them is returned. In other words, there should no more than one record of each parent_id apart from those having parent_id = 0.</p>
  
  <p>What could be the solution?</p>