• Sorry, my mistake, A and B are not the tables, just ignore that sentence.

    There are many tables which are joined to build the 2 result set and then these 2 result set are combined using union all to get the above result.

    There is no ddl stmt here. Tables are already created.