title: mysql IF in GROUP BY clause
body: <p>Is there a way do the if in group by clause?</p>
  
  <p>I have a query where I want to group the result based on the value of a column</p>
  
  <p>if the column is Null, i want the result to remain as it is but if not, i want to group it by that value? how do you do that?</p>
  
  <p>edit: sorry I think i should put a more specific example</p>
  
  <p>the columns below contains the id of category, thread and reply</p>
  
  <p>it's for a forum</p>
  
  <p>the ones with null values means they don't have any reply in them</p>
  
  <p>if the reply is null, i don't want to group it</p>
  
  <p><strong>the purpose is for counting the replies and the threads inside a category</strong></p>
  
  <p>i did not set the value for reply to be null, they are like that because of the result of a join</p>
  
  <pre><code>| category | thread | reply   |
  -------------------------------
  | 1        | 1      | 1       |
  | 1        | 1      | 2       |
  | 1        | 2      | 3       |
  | 2        | 3      | 4       |
  | 3        | 4      | 5       |
  | 3        | 4      | 6       |
  | 4        | 5      | null    |
  | 5        | 6      | null    |
  </code></pre>
  
  <p>then the result would be</p>
  
  <pre><code>| category | thread | reply |
  -----------------------------
  | 1        | 3      | 3     |
  | 2        | 1      | 1     |
  | 3        | 2      | 2     |
  | 4        | 1      | null  |
  | 5        | 1      | null  |
  </code></pre>