Saad Awan
Saad Awan

Reputation: 163

mysql data copy from one table to another without duplicate value

we have 2 table . we want to transfer table_1 data to table_2 with out duplicate data.

Table_1
----------
1

2

3

4
----------

Table_2
----------
2

4
----------

now we want to transfer Table_1 Values to Table_2 without duplicate. please tell me how to do in mysql query

Upvotes: 1

Views: 1390

Answers (2)

Priyanshu
Priyanshu

Reputation: 881

insert into table_2 
select * 
  from table_1 
 where column not in (select column from table_2);

Upvotes: 3

Zafar Malik
Zafar Malik

Reputation: 6844

First create unique index on the column (you want to keep unique) in table_2.

Now use below statement-

insert ignore into table_2 select * from table_1;

Upvotes: 2

Related Questions