i have 2 tables(result of two separate SQL queries and this result will be contained by List<Object> where each object represents 1 row of the database )
Table_1
- Dimension_1
- Dimension_2
- Fact_1
Table_2
- Dimension_1
- Dimension_2
- Fact_2
I want to join these two result in the RESULTSET AS
Table_Resultant
- Dimension_1
- Dimension_2
- Fact_1
- Fact_2
Due to some complication in querying part in my system i can’t issue single query for the resultant table, and due to these limitations i will have have to join the two results List <object>(table_1 & table_2) into table_resultant every time
what are the possible approach for the Problem?
Is creating a Temporary table(to join the two resultsets) in MYSQL can be a potential solution???
Yes I am allowed to create temporary tables in Mysql
YES,”COMPLEX” SQL is permitted on the 2 “Results” to GET the resultant_table
So you can do Union but not Join ? Could you clarify if you need to match values of Dimension1 and Dimension2 in the two source tables ? Or if you just need to take all values from both tables and merge them in the resultant one (in which case yes an Union might do the trick)
You need a full outer join, assuming that’s not possible in your query system, here’s the outline of a solution, assuming that:
That’s not the final solution, it will not return NULL for fact1 or 2 when the join doesn’t match. For that of course you’d have to use CASE, or maybe if your querying system thinks that max(NULL,1)=1
Full solution with Union:
If you can do a FULL OUTER JOIN on the two resultsets then it will look like this