anchor.diff:          end,
           {[], NewCtx},
           OrderBy),
  +    NewCtx2 = case FType of
  +        top_down -> NewCtx1;
  +        bottom_up -> Fun(ST, NewCtx1)
  +    end,
       {if Size > 0 ->
           " order by " ++ string:join(OrderByStr, ", ")
           ++ " ";
           true -> ""
        end
  -    , NewCtx1};
  +    , NewCtx2};
   
   % joins
  -foldi({JoinType, Tab} = ST, Fun, Ctx)
  +foldi(FType, {JoinType, Tab} = ST, Fun, Ctx)
    when (is_function(Fun,2) andalso (
           (JoinType =:= cross_join) orelse
           (JoinType =:= natural_join) orelse
           (JoinType =:= natural_inner_join)
        )) ->
  -    NewCtx = Fun(ST, Ctx),
  +    NewCtx = case FType of
  +        top_down -> Fun(ST, Ctx);
  +        bottom_up -> Ctx
  +    end,
       NewCtx1 = Fun(JoinType, NewCtx),
  -    {TabStr, NewCtx2} = foldi(Tab, Fun, NewCtx1),
  +    {TabStr, NewCtx2} = foldi(FType, Tab, Fun, NewCtx1),
  +    NewCtx3 = case FType of
  +        top_down -> NewCtx2;
  +        bottom_up -> Fun(ST, NewCtx2)
  +    end,
       {case JoinType of
           cross_join          -> " cross join ";
           natural_join        -> " natural join ";
           natural_inner_join  -> " natural inner join "
        end ++ TabStr
  -    , NewCtx2};
  -foldi({{JoinType,OptPartition,OptNatural},Tab,OptPartition1,OnOrUsing} = ST, Fun, Ctx)
  +    , NewCtx3};
  +foldi(FType, {{JoinType,OptPartition,OptNatural},Tab,OptPartition1,OnOrUsing} = ST, Fun, Ctx)
    when (is_function(Fun,2) andalso (
           (JoinType =:= full) orelse
           (JoinType =:= left) orelse
  
positive.code:                     CtxAcc1 = Fun(C, CtxAcc),
                      CtxAcc2 = Fun(T, CtxAcc1),
                      CtxAcc3 = Fun(N, CtxAcc2),
                      {SubAcc, CtxAcc4} = foldi(O, Fun, CtxAcc3),
                      {Acc ++ [lists:flatten([binary_to_list(C), " ", atom_to_list(T), "(", N, ") ", SubAcc])]
                      , CtxAcc4};
                  {C, {T, N, N1}, O} when is_binary(C) ->
  
negative.code: -ifdef(TEST).
  -include_lib("eunit/include/eunit.hrl").
  -include("sql_tests.hrl").
  
  %%-----------------------------------------------------------------------------
  %%                               EUnit test
  