mariadb-10.4

Getting Parent Child hierarchy

冷暖自知 提交于 2020-03-04 18:56:13
问题 I'm trying to get ancestors of a child (dog) upto Level 5. For Example in attached picture I'll be sending "Spencer di Casa Massarelli" and in result want to have associated parents (both father and mother). In my DB structure I've used father_id and mother_id. DB & version: 10.4.11-MariaDB Table Script: CREATE TABLE `dogs` ( `dog_id` int(11) NOT NULL, `name` varchar(255) DEFAULT NULL, `father_id` int(11) DEFAULT NULL, `moter_id` int(11) DEFAULT NULL, PRIMARY KEY (`dog_id`) ) ENGINE=InnoDB