MySQL function to return breadcrumb-like string from hierarchical structure Show create table:

CREATE TABLE `a` (
  `id` int(11) NOT NULL,
  `name` varchar(255) DEFAULT NULL,
  `parent_id` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `parent_id` (`parent_id`),
  CONSTRAINT `a_ibfk_1` FOREIGN KEY (`parent_id`) REFERENCES `a` (`id`) ON DELETE NO ACTION
) ENGINE=InnoDB DEFAULT CHARSET=latin1


Select:

+----+---------+-----------+
| id | name    | parent_id |
+----+---------+-----------+
|  1 | World   |         1 |
|  2 | Europe  |         1 |
|  3 | USA     |         1 |
|  4 | France  |         2 |
|  5 | Germany |         2 |
+----+---------+-----------+


Question:


how do I best define a function which, passed id 4 as an argument, returns:

"World > Europe > France"


This hierarchical "nesting" by "parent_id" could be arbitrarily deep, not just 3 levels deep.
delimiter //
create function derp(IN myId int) returns varchar(255) begin
    select concat(t1.name, ' &gt; ', t2.name, ' &gt; ' t3.name) from a t1 join a t2 on t1.parent_id=t2.id join a t3 on t2.parent_id = t3.id where t1.id=myId;
end//


Not tested, just off the top of my head.  For reference http://dev.mysql.com/doc/refman/5.5/en/create-procedure.html