How to get the value of related rows?
<p>I have a table like this:</p>

<pre><code>// QandA
+----+----------+----------------+------+---------+-----------+
| id | subject  | acceptedanswer | type | related | id_author |
+----+----------+----------------+------+---------+-----------+
| 1  | subject1 | NULL           | 0    | NULL    | 123       |
| 2  |          | 1              | 1    | 1       | 452       |
| 3  | subject2 | NULL           | 0    | NULL    | 635       |
| 4  |          | 1              | 1    | 3       | 432       |
| 5  |          | NULL           | 1    | 1       | 246       |
+----+----------+----------------+------+---------+-----------+

/* columns explanations:
- acceptedanswer can be NULL, 0, 1. (0 and NULL are identical). (it is NULL for questions)
- type is 0 for questions and 1 for answers.
- related is NULL for questions. For answers is containing the number of its own question
*/
</code></pre>

<p>Well I have two parameters:</p>

<ul>
<li><code>id</code> number of an answer: <code>$id = 5</code></li>
<li><code>id_author</code> of that answer <code>$id_author = 246</code></li>
</ul>

<p>Now I'm trying to get these two things:</p>

<ul>
<li>the subject of its owe question</li>
<li>specifying has its own question any accepted-answer or not. </li>
</ul>

<p>Here is my <strong>query:</strong></p>

<pre><code>SELECT t2.subject
FROM qanda t1
JOIN qanda t2 ON t1.related = t2.id AND t2.type = 0
WHERE t1.id = $id AND t2.id_author = $id_author
</code></pre>

<p><strong>Current result:</strong></p>

<pre><code>+----------+
| subject1 |
+----------+
</code></pre>

<p><strong>Expected result:</strong></p>

<pre><code>+----------+---+
| subject1 | 1 |
+----------+---+
--           ^ this 1 means the question of this answer has a accepted answer
--           ^ this should be 0 if there isn't any accepted answer for that question
</code></pre>

<p>How can I do that?</p>