SQL Language (MOSC)

MOSC Banner

How to use union to re-arrange query results?

edited Sep 18, 2012 8:00PM in SQL Language (MOSC) 12 commentsAnswered ✓
Hi there,

I have following situation: 3 tables x, y, z.  They have one column in common and one column different like this:

Table x                            Table y                          Table z

-------------                  ---------------                  ---------------

A     a                           A          1                      A          I

B      b                          B           2                      B          II

C      c                          C           3                      C          III

--------------                ------------------               ----------------

After query, I like to arrange them like this:

                     x                  y              z

-------------------------------------------------

A                 a                    1              I

B                  b                   2              II

C                  c                   3              III

-------------------------------------------------

I thought this script:

select x.column1, x.column2 , null, null from table x  union

select y.column1,null, y.column2, null from table y union

select z.column1, null, null, z.column2 from table z

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center