looking into your question and reading your comment - “I need to get ONE specific question, with ALL answers and comments”, I think you want to show each question, followed by his answer, and then his comments. Right?
And if so, this is your request:
SELECT `id`, (CASE WHEN `entry_type` = 'question' THEN CONCAT(`id`, '-', `parent_id`) WHEN `entry_type` = 'answer' THEN CONCAT(`id`, '-', `parent_id`) WHEN `entry_type` = 'comment' THEN CONCAT(`parent_id`, '-', `id`) END) `sort_order`, `entry_type`, `entry_content` FROM `questions` ORDER BY `sort_order`;
The above request will give you every question, followed by his first answer, and then comments on his first answer; then the second answer, then comments on the second answer, etc.
So, for the INSERT you entered, this will be the output:
+----+------------+------------+--------------------------+ | id | sort_order | entry_type | entry_content | +----+------------+------------+--------------------------+ | 1 | 1-1 | question | How do I does SQL? | | 2 | 2-1 | answer | Easy, you eat cheese! | | 3 | 2-3 | comment | WTF are you on noobass?! | | 6 | 2-6 | comment | 3 | | 4 | 4-1 | answer | blah | | 5 | 4-5 | comment | blah2 | +----+------------+------------+--------------------------+
Hope this helps.
EDIT : Updated request for answers and comments for ONE question only
SELECT `id`, (CASE WHEN (`entry_type` IN ('question', 'answer')) THEN `id` WHEN `entry_type` = 'comment' THEN `parent_id` END) `sort_order_1`, (CASE WHEN (`entry_type` IN ('question', 'answer')) THEN `parent_id` WHEN `entry_type` = 'comment' THEN `id` END) `sort_order_2`, (CASE WHEN (`entry_type` IN ('question', 'answer')) THEN `parent_id` WHEN `entry_type` = 'comment' THEN (SELECT `Q1`.`parent_id` FROM `questions` `Q1` WHERE `Q1`.`id` = `Q`.`parent_id`) END) `question_id`, `entry_type`, `entry_content` FROM `questions` `Q` HAVING `question_id` = 1 ORDER BY `sort_order_1`, `sort_order_2`;
OUTPUT:
+----+--------------+--------------+-------------+------------+--------------------------+ | id | sort_order_1 | sort_order_2 | question_id | entry_type | entry_content | +----+--------------+--------------+-------------+------------+--------------------------+ | 1 | 1 | 1 | 1 | question | How do I does SQL? | | 2 | 2 | 1 | 1 | answer | Easy, you eat cheese! | | 3 | 2 | 3 | 1 | comment | WTF are you on noobass?! | | 6 | 2 | 6 | 1 | comment | 3 | | 4 | 4 | 1 | 1 | answer | blah | | 5 | 4 | 5 | 1 | comment | blah2 | +----+--------------+--------------+-------------+------------+--------------------------+
You can change the HAVING part to get answers and comments on a specific issue. Hope this helps!
EDIT 2 : another possible implementation is possible (but I think this may have some implications for large tables):
SELECT `a`.`id` AS `question_id`, `a`.`entry_content` AS `question`, `b`.`id` AS `answer_id`, `b`.`entry_content` AS `answer`, `c`.`id` AS `comment_id`, `c`.`entry_content` AS `comment` FROM `questions` `a` LEFT JOIN `questions` `b` ON (`a`.`id` = `b`.`parent_id` AND `b`.`entry_type` = 'answer') LEFT JOIN `questions` `c` ON (`b`.`id` = `c`.`parent_id` AND `c`.`entry_type` = 'comment') WHERE `a`.`entry_type` = 'question' AND `a`.`id` = 1 ORDER BY `a`.`id`, `b`.`id`, `c`.`id`;
OUTPUT:
+----+--------------------+------+-----------------------+------+--------------------------+ | id | question | id | answer | id | comment | +----+--------------------+------+-----------------------+------+--------------------------+ | 1 | How do I does SQL? | 2 | Easy, you eat cheese! | 3 | WTF are you on noobass?! | | 1 | How do I does SQL? | 2 | Easy, you eat cheese! | 6 | 3 | | 1 | How do I does SQL? | 4 | blah | 5 | blah2 | +----+--------------------+------+-----------------------+------+--------------------------+