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 6776347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:01:01+00:00 2026-05-26T16:01:01+00:00

I need to merge two tables: Both have a primary key-column date, but with

  • 0

I need to merge two tables:

  • Both have a primary key-column date, but with different values (different time intervals).
  • Both have different (unknown) columns: I don’t know the names of the columns (same column-name may occur in both tables), I don’t know how many columns, but all of the same type.

An example:

table1
date       | colA | colB | colC
2011-02-02 | 1.09 | 1.03 | 1.04

table2
date       | col1 | col2 | col3 | col4
2011-02-03 | 1.03 | 1.02 | 1.07 | 1.03

the result of the query should look like this:

tableResult
date       | colA | colB | colC | col1 | col2 | col3 | col4
2011-02-02 | 1.09 | 1.03 | 1.04 | null | null | null | null
2011-02-03 | null | null | null | 1.03 | 1.02 | 1.07 | 1.03

This will not work:

  • INNER JOIN because it will only return the intersection between table1 and table2,
  • OUTER JOIN returns intersection + values only from left table (or right table if right join is used)
  • UNION because the count of columns may differ.

Any Ideas?

Christoph

  • 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-26T16:01:02+00:00Added an answer on May 26, 2026 at 4:01 pm

    You can create a temp table with the union of just the date column, and then use the temp table to left outer join with the other 2.

    Example:

    DROP TABLE temptbl IF EXISTS;
    CREATE TEMPORARY TABLE temptbl (myDate DATETIME PRIMARY KEY)
        AS (SELECT MyDate FROM table1)
        UNION (SELECT MyDate FROM table2)
        ORDER BY MyDate;
    SELECT * FROM temptbl
        LEFT OUTER JOIN table1 USING (MyDate)
        LEFT OUTER JOIN table2 USING (MyDate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, each one has a primary ID column as key. I
I have two tables which both contain 'pipe separated values' e.g: Table 1: DataField_A
I have a situation where I need to merge two product tables into one
I need to merge two SELECT statements. There are two tables in my database,
We currently have merge replication set up to merge certain tables between two databases.
I need to merge two tables, with the contents of the second overwriting contents
I am using Oracle, I need to merge two queries, but i would like
DESCRIPTION I have two datasets with information that I need to merge. The only
I need to merge two XML documents, overwriting the overlapsed attributes and elements. For
I need to be able to merge two (very simple) JavaScript objects at runtime.

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.