how to flatten child tables into parent
Since you have not provided any RDBMS I've tried to post an answer that should work in more than one system.

Records can be ordered by both ranks and numbered using row_number() window function.




select row_number() over (order by r1, r2) id, name
from (
      select t.name as [name], t.[rank] r1, 0 as r2
      from   thing t
      union all
      select w.name as [name], t.[rank] r1, w.[rank] r2 
      from   widget w
      join   thing t
      on     t.id = w.thing_id
     ) x;
GO



id | name           
:- | :--------------
1  | thing blue     
2  | thing yellow   
3  | thing green    
4  | widget bean    
5  | widget cucumber
6  | thing red      



dbfiddle here