Hi Jeff,
my data structure is like:
table1: source system data(system ID,Date, Product ID,
accoutID1, accountID2.....)
table2: source system adjustment data(system ID,Date,
Product ID, accoutID1, accountID2.....)
table3" GL data(Date, Product ID, accoutID1,
accountID2.....)
table4: GL adjustment data(Date, Product ID, accoutID1,
accountID2.....)
table5: SIF adjustment data(Date, Product ID, accoutID1,
accountID2.....)
I need to use the 5 table to create a GL reconciliation
report, the requirement is output all balances in source
sytem, source system adjustment, GL, GL adjustment and SIF
adjustment of a product. if a product is not from a
system, show it in GL, GL adjustment, SIF part(if any),
vice versa, if a product does not exist in GL, show the
balance in system part(if any).
so my query structure is like this:
1.first UNION data in source system part
select * from table1 left join table2
UNION
select * from table1 right join table2
2.second UNION data in GL part
selcet * from table3 left join
(select * from table4 left join table5
UNION
select * from table4 right join table5)
UNION
selcet * from table3 right join
(select * from table4 left join table5
UNION
select * from table4 right join table5)
3. UNION data on system part and GL part.
select * from
(select * from table1 left join table2
UNION
select * from table1 right join table2) left join
(selcet * from table3 left join
(select * from table4 left join table5
UNION
select * from table4 right join table5)
UNION
selcet * from table3 right join
(select * from table4 left join table5
UNION
select * from table4 right join table5))
UNION
select * from
(select * from table1 left join table2
UNION
select * from table1 right join table2) right join
(selcet * from table3 left join
(select * from table4 left join table5
UNION
select * from table4 right join table5)
UNION
selcet * from table3 right join
(select * from table4 left join table5
UNION
select * from table4 right join table5))
I ignore some key words, Can you see some sub query is
written more than once.
Is there a better way not to use UNION to combine the left
join and right join? Thanks very much
regards
Shu