Matthew Barbara
Matthew Barbara

Reputation: 13

MySQL Merging two columns

I am having a problem merging two columns from separate tables into one column. Here's the scenario, I have 2 tables each with different columns containing dates. I want to create a temporary table containing a column of all the dates from both original tables.

This is how I want it to turn out:

   Table: Table A
         ----------
Column: DateServiced
        2017-01-01 (1)
        2017-05-01 (2)

   Table: Table B
         ----------
Column: DateShipped
        2017-03-01 (3)
        2017-04-01 (4)

And they would merge into one column on a temporary table.

   Table: Temp Table
         ------------
 Column: MergedDates
         2017-01-01 (1)
         2017-03-01 (3)
         2017-04-01 (4)
         2017-05-01 (2)

NOTE I cannot alter the original tables, and it is fine if there are duplicate dates. The order does matter but whether it's newest or oldest first does not matter.

Upvotes: 1

Views: 58

Answers (1)

Sudipta Mondal
Sudipta Mondal

Reputation: 2572

UNION should help you

SELECT DateServiced
  FROM TABLE A
 UNION 
SELECT DateShipped
  FROM TABLE B;

Upvotes: 2

Related Questions