title: How can I select the last edited version of the post?
body: <p>I have a question and answer website like SO. Also I have a table which contains both the questions and answers and their edited version. Here is my table structure:</p>
  
  <pre><code>// QandA
  +----+---------+---------------------------+---------+------+-----------+
  | id |  title  |            body           | related | type | edited_id |
  +----+---------+---------------------------+---------+------+-----------+
  | 1  | title1  | question content          | NULL    | 0    | NULL      |
  | 2  |         | answer content            | 1       | 1    | NULL      | 
  | 3  | title2  | question content          | NULL    | 0    | NULL      |
  | 4  |         | answer content            | 3       | 1    | NULL      |
  | 5  |         | answer content            | 1       | 1    | NULL      |
  | 6  |         | answer content (edited)   | NULL    | 1    | 2         |
  | 7  | title3  | question content          | NULL    | 0    | NULL      |
  | 8  | title1  | question content (edited) | NULL    | 0    | 1         |
  | 9  |         | answer content            | 7       | 1    | NULL      |
  | 10 | title1  | question content (edited) | NULL    | 0    | 1         |
  | 11 | title3  | question content (edited) | NULL    | 0    | 7         |
  +----+---------+---------------------------+---------+------+-----------+
  </code></pre>
  
  <h3>Column explanations:</h3>
  
  <p><strong><code>related</code> column:</strong></p>
  
  <ul>
  <li><code>NULL</code> for both questions and edited version of questions/answers</li>
  <li><code>{the id of its own question}</code> for answers</li>
  </ul>
  
  <p><strong><code>type</code> column:</strong></p>
  
  <ul>
  <li><code>0</code> for questions</li>
  <li><code>1</code> for answers</li>
  </ul>
  
  <p><strong><code>edited_id</code> column:</strong> <em>(the id of original post)</em></p>
  
  <ul>
  <li><code>NULL</code> means it is a original question/answer</li>
  <li><code>{any number}</code> means it is a edited version of a question/answer.</li>
  </ul>
  
  <hr>
  
  <p>Now I need a query to select a question and all its answers. Noted that I need to select <strong>the last</strong> edited version of them <em>(if they have been edited)</em>.</p>
  
  <p><strong>Example1:</strong> I have this value: <code>:id = 1</code> and I want this output:</p>
  
  <pre><code>+----+---------+---------------------------+---------+------+-----------+
  | id |  title  |            body           | related | type | edited_id |
  +----+---------+---------------------------+---------+------+-----------+
  | 10 | title1  | question content (edited) | NULL    | 0    | 1         |
  | 6  |         | answer content (edited)   | NULL    | 1    | 2         |
  | 5  |         | answer content            | 1       | 1    | NULL      |
  +----+---------+---------------------------+---------+------+-----------+
  </code></pre>
  
  <p><strong>Example2:</strong> I have this value: <code>:id = 3</code> and I want this output:</p>
  
  <pre><code>+----+---------+---------------------------+---------+------+-----------+
  | id |  title  |            body           | related | type | edited_id |
  +----+---------+---------------------------+---------+------+-----------+
  | 3  | title2  | question content          | NULL    | 0    | NULL      |
  | 4  |         | answer content            | 3       | 1    | NULL      |
  +----+---------+---------------------------+---------+------+-----------+
  </code></pre>
  
  <p><strong>Example2:</strong> I have this value: <code>:id = 7</code> and I want this output:</p>
  
  <pre><code>// QandA
  +----+---------+---------------------------+---------+------+-----------+
  | id |  title  |            body           | related | type | edited_id |
  +----+---------+---------------------------+---------+------+-----------+
  | 11 | title3  | question content (edited) | NULL    | 0    | 7         |
  | 9  |         | answer content            | 7       | 1    | NULL      |
  +----+---------+---------------------------+---------+------+-----------+
  </code></pre>
  
  <hr>
  
  <p>Here is my current query:</p>
  
  <pre><code>SELECT *
  FROM QandA
  WHERE (id = :id AND type = 0) OR
        (related = :id AND type = 1)
  ORDER BY type -- noted that the order of answers doesn't matter
  </code></pre>
  
  <p>As you see, my query doesn't support <em>edited version</em>. Anyway, how can I replace edited version of posts when there is a edited row of that post?</p>
  
  <p><strong>Note:</strong> Please don't tell me <em>"don't keep both the questions and answers in the same table"</em>, Because I know it. But now I need to solve problem above.</p>