Reputation: 89
I have imported several large csv
's and I am looking to create a merged table from several imports.
So lets say I have 2 tables.
table1
:
title
ben
rupert
table2
:
title
karen
jill
and I want to either populate an empty table or create one on the fly.
//NewTable
title
ben
rupert
karen
jill
I've tried using SQL
like this - but I am getting NewTable
undefined variable issues
select *
into `NewTable`
from(
select * from `table1`
union all
select * from `table2`
union all
)t
Upvotes: 0
Views: 52
Reputation: 2964
Create NewTable
first then:
INSERT INTO NewTable
SELECT * FROM table1
UNION ALL
SELECT * FROM table2
An alternate way in which you wouldn't need to create the table first, off the top of my head would be:
SELECT *
INTO NewTable
FROM table1
And then perform the insert from the second table:
INSERT INTO NewTable
SELECT * FROM table2
Upvotes: 2