I am doing a UNION between 3 tables. To put you in the picture, one table is considered as the main table and the 2 other tables are considered as sub tables. The 2 sub tables have always the same number of records for each case. So I wanted to make a union between these 3 tables, in this union I'd like to repeat the information in the column fetched in the main table and list the information the 2 sub tables where every line in sub table 1 correspond to the line in sub table 2. I cannot put the real code because of professional reasons so here is a simple example corresponding to my real case. Consider a table called Author (Author_ID, Author_FirstName, Author_LastName). This table will be our main table. Then consider we have a table called Adresses (Adress_ID, Street_Coord, Author_ID), this will be our sub table 1. Then consider the table called Cities (City_ID, City_Name, Author_ID). Our author X has 2 adresses in 2 cities. When I execute my query I get the result R1 which is totally logical, but I want to modify my query to get the result R2. Could you please help me to change my query to get the result R2?
SQL Query:
SELECT "Author"."Author_ID", "Author"."Author_FirstName", "Author.Author_LastName",
TO_CHAR(NULL) AS "Street_Coord", TO_CHAR(NULL) AS "City_Name"
FROM "Author"
WHERE "Author"."Author_ID"='X'
UNION
SELECT TO_NUMBER(NULL) AS "Author_ID", TO_CHAR(NULL) AS "Author_FirstName", TO_CHAR(NULL) AS "Author_LastName",
"Adresses"."Street_Coord", TO_CHAR(NULL) AS "City_Name"
FROM "Adresses"
WHERE "Adresses"."Author_ID"='X'
UNION
SELECT TO_NUMBER(NULL) AS "Author_ID", TO_CHAR(NULL) AS "Author_FirstName", TO_CHAR(NULL) AS "Author_LastName",
TO_CHAR(NULL) AS "Street_Coord", "Cities"."City_Name"
FROM "Cities"
WHERE "Cities"."Author_ID"='X'
Result R1:
ID_AUTHOR | AUTHOR_FirstName | AUTHOR_LastName | Street_Coord | City_Name |
----------------------------------------------------------------------------------
X |James | Conor | NULL | NULL |
----------------------------------------------------------------------------------
X |NULL | NULL | 1245 rich st | NULL |
----------------------------------------------------------------------------------
X |NULL | NULL | 154 music st | NULL |
----------------------------------------------------------------------------------
X |NULL | NULL | NULL | Madrid |
----------------------------------------------------------------------------------
X |NULL | NULL | NULL | Barcelona |
----------------------------------------------------------------------------------
Result R2: I want you to help get this result please:
ID_AUTHOR | AUTHOR_FirstName | AUTHOR_LastName | Street_Coord | City_Name |
----------------------------------------------------------------------------------
X |James | Conor | 1245 rich st | Madrid |
----------------------------------------------------------------------------------
X |James | Conor | 154 music st | Barcelona |
----------------------------------------------------------------------------------
Many thanks, Walloud