Assume the following table: CREATE TABLE test ( id MEDIUMINT UNSIGNED NOT NULL AUTO_INCREMENT, parent MEDIUMINT UNSIGNED NOT NULL DEFAULT 0, name VARCHAR(60) NOT NULL, PRIMARY KEY (id) );
INSERT INTO test (name) VALUES ('root'); SELECT @root_id:=id FROM test WHERE name = 'root'; INSERT INTO test (name,parent) VALUES ('sub 1',@root_id),('sub 2',@root_id); SELECT @id:=id FROM test WHERE name = 'sub 1'; INSERT INTO test (name,parent) VALUES ('sub 1.1',@id); Is it possible to create a query that create a result which looks something like: id name parent ------------------------------ <id> root <id> sub 1 root <id> sub 1.1 sub 1 <id> sub 2 root where <id> is the actual value of the id field. I'm also looking for a query where I select one record based on id and get a output like "root > sub 1 > sub 1.1", if this is possible. Or do I have to do this in a loop in my PHP code? -- Jørn Dahl-Stamnes homepage: http://www.dahl-stamnes.net/dahls/ -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]