I don't have atm tables where I could test it, but this might work, at least without using data:
SELECT * FROM table1 LEFT JOIN table2 ON table1.id = table2.id WHERE 1 ORDER BY IF( table2.id, table1.id, table1.name )
Also I don’t know what the order will look like if table2.id is sometimes null, it seems very unstable.
Nurickan
source share