Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 335371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:08:33+00:00 2026-05-12T10:08:33+00:00

i have 2 tables(result of two separate SQL queries and this result will be

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T10:08:33+00:00Added an answer on May 12, 2026 at 10:08 am

    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:

    1. Fact1 and 2 are >=0 ints and 
    2. no row in tablex where factx is null.
    
    Select dimension1,dimension2,max(Fact1),max(Fact2) 
    From (Select dimension1, dimension2, Fact1, -1 as Fact2 
          UNION 
          Select dimension1, dimension2, -1 , Fact2 ) 
    GROUP by dimension1, dimension2 
    

    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:

    Select dimension1, dimension2,  
           CASE WHEN max(Fact1) = -1 THEN NULL ELSE Fact1 END,  
           CASE WHEN max(Fact2) = -1 THEN NULL ELSE Fact2 END,  
    From (Select dimension1, dimension2, Fact1, -1 as Fact2  
          UNION 
          Select dimension1, dimension2, -1 , Fact2 )  
    GROUP by dimension1, dimension2  
    

    If you can do a FULL OUTER JOIN on the two resultsets then it will look like this

    Select isnull(t1.dimension1, t2.dimension1),   
           isnull(t1.dimension2,t2.dimension2),  
           t1.fact1,  
           t2.fact2  
    FROM table1 t1 
    OUTER JOIN table2 t2   
    ON t1.dimension1=t2.dimension1 and t1.dimension2=t2.dimension2   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables for a facebook and twitter stream. Those tables have to
I have four tables, user , user_billingprofile , user_shippingprofile , and user_address . user:
Initially I have user input decimal numbers (0 - 15), and I will turn
I have a comprehensive web application with the use of lots of nested tables.
My team has a service deployed internally, and part of this service is a
In this case, I'm working on a project that involves a database of library
I'd like to write the following as a MySQL SELECT statement to cut down
Not sure on what the best practices are for dealing with NULL values when
I'm selecting columns from one table and would like to select all values of
There is a hypothetical table called Table1, with the columns: id condition 1 condition

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.