0

I have two table: table1, table2. I need to mix them and then create a new table.

Here is my example:

// table1:
+------+------+
| col1 | col2 |
+------|------+
| 111  |  222 |
| 333  |  444 |
+------+------+

// table2:
+------+------+
| col1 | col2 |
+------|------+
| 555  |  666 |
| 777  |  888 |
+------+------+

So, I need something like this:

// new_table:
+------+------+
| col1 | col2 |
+------|------+
| 111  |  222 |
| 333  |  444 |
| 555  |  666 |
| 777  |  888 |
+------+------+

How can I do that ?

Shafizadeh
  • 9,960
  • 12
  • 52
  • 89

2 Answers2

1

use union

create table table3 as
    select col1, col2 from table1
    union all
    select col1, col2 from table2
juergen d
  • 201,996
  • 37
  • 293
  • 362
  • you did not use of `create` for creating a new table ? – Shafizadeh Aug 02 '15 at 13:28
  • You are welcome. But no, I don't communicate outside this site. – juergen d Aug 02 '15 at 13:38
  • I have a question about `TRIGGER` [here](http://stackoverflow.com/questions/31920600/how-to-create-a-update-trigger-for-increase-decrease-1-number-to-total-votes-num) (part of Edit). I think you can solve it, please take a look at it, tnx. – Shafizadeh Aug 11 '15 at 21:53
0

If you want to remove the same items, you can

create table new_table as
    select col1, col2 from table1
    union
    select col1, col2 from table2
Sean Zhang
  • 108
  • 6