Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

join two tables into one big table

Tags:

sql

database

I have two tables with the same columns, and I need to copy one table's rows to the other table's rows to create one big table with all the values from both tables. Right now I am doing this query to return the same thing:

SELECT col1, col2, col3 from Table1
union
SELECT col1, col2, col3 from Table2

However, it seems horribly inefficient, and on my system is very slow (returns 1210189 records).

like image 615
David Ackerman Avatar asked Nov 29 '08 09:11

David Ackerman


2 Answers

May it work to just do:

SELECT col1, col2, col3 
INTO Table1
FROM Table2 
like image 110
Tommy Avatar answered Oct 13 '22 02:10

Tommy


Start with union all:

select col1, col2, col3 from Table1
union all
select col1, col2, col3 from Table2

Your query is trying to deduplicate things, which would slow it down considerably.

like image 33
Dustin Avatar answered Oct 13 '22 02:10

Dustin