which is better one big query or multiple small query?

Bry picture Bry · May 23, 2016 · Viewed 28.9k times · Source

which is better and efficient? one big query then just process the fetched query in the php or from php function will just create a loop function that queries small data. Please consider also that the table can be big (thousands of raw). Thanks.

Comments table

id | parent | msg
---+--------+---------      
1  |   0    | hello   
2  |   1    | hi      
3  |   2    | whats up       
4  |   3    | yow       
5  |   1    | hellow   
6  |   2    | nice       
7  |   0    | great   

Expected output is this:

        Array
        (
            [0] => Array
                (
                    [id] => 1
                    [parent] => 0
                    [value] => hello
                    [child] => Array
                        (
                            [0] => Array
                                (
                                    [id] => 2
                                    [parent] => 1
                                    [value] => hi
                                    [child] => Array
                                        (
                                            [0] => Array
                                                (
                                                    [id] => 3
                                                    [parent] => 2
                                                    [value] => whats up
                                                    [child] => Array
                                                        (
                                                            [0] => Array
                                                                (
                                                                    [id] => 4
                                                                    [parent] => 3
                                                                    [value] => yow
                                                                )
                                                        )
                                                )
                                            [1] => Array
                                                (
                                                    [id] => 6
                                                    [parent] => 2
                                                    [value] => nice
                                                )
                                        )
                                )
                            [1] => Array
                                (
                                    [id] => 5
                                    [parent] => 1
                                    [value] => hellow
                                )
                        )
                )
            [1] => Array
                (
                     [id] => 7
                    [parent] => 0
                    [value] => great
                )