SQL Query for the following structure
It took me a while to figure this one out.

        SELECT  t1.id      + 1 AS `start`, 
                MIN(t3.id) - 1 AS `stop`
          FROM (SELECT  table1.id
                  FROM (SELECT treeleft  AS id FROM structure
                        UNION ALL
                        SELECT treeright AS id FROM structure
                       )  
                    AS  table1) 
             AS t1
LEFT OUTER JOIN (SELECT  table2.id
                   FROM (SELECT treeleft  AS id FROM structure
                         UNION ALL
                         SELECT treeright AS id FROM structure 
                        )  
                     AS  table2)  
             AS  t2 
             ON  t1.id = t2.id - 1
LEFT OUTER JOIN (SELECT  table3.id
                   FROM (SELECT treeleft  AS id FROM structure
                         UNION ALL
                         SELECT treeright AS id FROM structure
                        ) 
                     AS  table3) 
             AS  t3
             ON  t1.id &lt; t3.id
          WHERE  t2.id IS NULL 
            AND  t3.id IS NOT NULL
       GROUP BY  t1.id, 
                 t2.id;