I have two database tables with a structure as follows:
page_info
- page_id (int)
- parent_page_id (int)
- page_title (varchar)
page_order
- page_order_id (int)
- parent_page_id (int)
- page_id (int)
- page_order (int)
(FYI the page_info table has been heavily cut down from what is actually there, these are the only fields at play here however.)
Is there a way to pull out the entire nested structure in a flat structure in the correct order with one, relatively fast SQL query?
The actual problem I am trying to solve is the current implementation we have is far too slow and coupled too closely to our CMS. A heavy, ugly recursive PHP function is currently used to build the data and it's causing bottlenecks in our application, therefore perhaps an SQL query to speed it up isn't necessarily the solution, but I'd love to see people thoughts nonetheless.