madhur
madhur

Reputation: 1001

INSERT INTO ... SELECT in mysql

I have a big table(more than 60k rows), I am trying to copy unique rows from this table to another table. Query is as follows

INSERT INTO tbl2(field1, field2) 
SELECT DISTINCT field1, field2 
   FROM tbl1;

But it is taking ages to run this query, can someone suggest any way to accelerate this process

Upvotes: 0

Views: 184

Answers (2)

Saxon
Saxon

Reputation: 937

Execute a mysqldump of your table, generating a sql file, then filter duplicated data with a shell command:

cat dump.sql | uniq > dump_filtered.sql

Check the generated file. Then create your new table and load your dump_filtered.sql file with LOAD DATA INFILE.

Upvotes: 1

techhunter
techhunter

Reputation: 693

Try this:

1. drop the destination table: DROP DESTINATION_TABLE;
2. CREATE TABLE DESTINATION_TABLE AS (SELECT * FROM SOURCE_TABLE);

Upvotes: 0

Related Questions