this qurey used for fetch data
SELECT qa_posts.postid AS qposid,qa_posts.content AS qcontent,
answer.postid AS aid,
answer.parentid AS aparentid,
answer.type AS atype,
comment.parentid AS cparent,
comment.type AS ctype,
comment.content AS ccontent
FROM qa_posts
LEFT JOIN qa_posts answer ON qa_posts.postid=answer.parentid
LEFT JOIN qa_posts comment ON answer.postid=comment.parentid
WHERE qa_posts.postid=1
ORDER BY qa_posts.parentid;
but the results dose not like the following query
SELECT * FROM qa_posts WHERE postid=1
UNION
SELECT * FROM qa_posts WHERE parentid=1
UNION
SELECT * FROM qa_posts WHERE parentid IN (SELECT postid parentid FROM qa_posts WHERE parentid=1)
ORDER BY parentid;
The second query results are not sorted in tandem.I need results like this
| id | parentid | type |
+------+----------+-------+
| 1 | 0 | Q |
+------+----------+-------+
| 5 | 1 | C |
+------+----------+-------+
| 2 | 1 | A |
+------+----------+-------+
| 4 | 2 | C |
+------+----------+-------+
| 8 | 2 | C |
+------+----------+-------+
| 6 | 1 | A |
+------+----------+-------+
| 7 | 6 | C |
+------+----------+-------+
| 11 | 6 | C |
+------+----------+-------+
.