I've got the following table that should manage tasks and their sub-tasks:
Code:
CREATE TABLE `tasks` (
`idTask` int(10) unsigned NOT NULL auto_increment,
`idParentTask` int(10) unsigned default NULL,
`description` text NOT NULL,
`idActor` int(10) unsigned NOT NULL,
`requiredDate` datetime default NULL,
`priority` int(10) unsigned NOT NULL,
`completedDate` datetime default NULL,
`timeTaken` varchar(45) default NULL,
`createdDate` timestamp NOT NULL default CURRENT_TIMESTAMP,
PRIMARY KEY (`idTask`)
)
Currently I can get a list of tasks from it via:
Code:
SELECT
t0.idTask AS t0_idTask,
t0.description AS t0_description,
t1.idTask AS t1_idTask,
t1.description AS t1_description,
FROM tasks t0
LEFT OUTER JOIN tasks t1
ON t1.idParentTask = t0.idTask
WHERE t0.idParentTask IS NULL
ORDER BY t0.idTask, t1.idTask
I've got two problems with it, however... well, two symptoms of the same problem:
1. Sub-tasks are listed on the same row of the resultset as their parent task.
2. If I want to add another level to the query; "sub-sub-tasks", I've got to manually add more fields/joins to the query.
Is there a way to write an infinitely scaling version of this? One that'll output (for instance) a row for a "main" task, then a row for its sub-task, then a row for the sub-task of that sub-task, and then a row for the next main task, and so on ad infinitum? Or am I hopelessly wrong?