I have 4 tables, who all relate to each other in such a way that:
TB1 <- TB2 <- TB3 <- TB4
meaning that TB4 holds elements that belongs to a single row in TB3, TB3 holds elements that belongs to a single row in TB2 and finally TB2 holds data that belongs to a single row in TB1.
i made this illustration to try to make it more clear

(edit: DB was suppose to be TB as in table)
I have tried to achieve this by using subqueries as follows:
SELECT TB1.id AS TB1_ID,
(SELECT TB2.id AS TB2_ID,
(SELECT TB3.id AS TB3_ID,
(SELECT TB4.id AS TB4_ID
FROM `TB4` AS TB4 WHERE TB4.TB3_id = TB3.id) AS C
FROM `TB3` AS TB3 WHERE TB3.TB2_id = TB2.id) AS B
FROM `TB2` AS TB2 WHERE TB2.TB1_id = TB1.id) AS A
FROM `TB1` AS TB1
yet my logic must be flawed: or there is something i am missing about querying related data: as this returns null, even though i know that the tables holds the necessary informations needed to make such a cross combination.
The desired result is a set of nested arrays within an array: one nested array for each tables. so that we ends up with a structure like:
{*, A{*, B{*, C{*} } } }
so that each row from TB1 contains a multidimensional array of elements from TB2 as a variable and each row form TB2 contains a multidimensional array of elements from TB3 as an element and so on...
I have also tried to pull all information as separate queries and then joining them in JS, however turned out to be quit heavy: so i would truly appreciate if anyone knew how to do this in a proper way - thanks a lot in advance
PS. im trying it in my local environment, through use of XAMPP: does this create a problem ?