romi
romi

Reputation: 643

Insert missing data only in MySQL

I have two tables, the first table has 400 rows. The second table holds the same records with the same count. Now the first table row count increases to 450. I want to insert only those 50 new rows into the second table. I don't need to update the first 400 records.

I am setting the unique index for the particular field (like empid). Now when I insert the first table data it returns the following error:

Duplicate entry 'xxxx' for key 'idx_confirm'

Please help me to fix this error.

Am using the below code to insert the record. But it allows duplicate entry..

insert ignore into tbl_emp_confirmation (fldemp_id,fldempname,fldjoindatefldstatus)
select fldempid, fldempname,DATE_FORMAT (fldjoindate,'%Y-%m-%d') as fldjoindate,fldstatus from tblempgeneral as n;

Upvotes: 0

Views: 1269

Answers (1)

Thilo
Thilo

Reputation: 17735

Modify your INSERT ... statement to INSERT IGNORE ....

See for example this post for an explanation.

You need to make sure that you have a unique index that prevents any duplicates, such as on the primary key.

Upvotes: 2

Related Questions