Oracle SQL: Can I combine columns from different tables into one table? -
i wonder if can combine columns different tables 1 results.
table a: id cola colb 1 b table b: id colc cold cole 1 c1 d1 e1 1 c2 d2 e2 table c: id colf colg 1 f g
expected results:
id cola colb colc cold cole colf colg 1 b c1 d1 e1 f g 1 c2 d2 e2
is there way combine columns different tables one?
thank in advance.
i 'simple' solution full outer join
, however, not give gaps have second row (because tablea contains 1 row).
so, solve that, can make little more complex , generate numbers per id each of tables. can make full outer join on each of subselects, , use generated row number second field in join. way, won't cartesian product, , you'll result drew it, gaps missing rows.
i don't have database @ hand test it, let me know if works.
select coalesce(a.id, b.id, c.id) id, a.cola, a.colb, b.colc, b.cold, b.cole, c.colf, c.colg (select id, row_number() on (partition id order cola) rownumber, cola, colb tablea t) full outer join (select id, row_number() on (partition id order colc) rownumber, colc, cold, cole tableb t) b on b.id = a.id , b.rownumer = a.rownumber full outer join (select id, row_number() on (partition id order colf) rownumber, colf, colg tablec t) c on c.id = nvl(a.id, b.id) , c.rownumer = a.rownumber
Comments
Post a Comment