#1062 - duplicate entry '' for key 'primary'

Venkateshwaran Selvaraj picture Venkateshwaran Selvaraj · Sep 25, 2013 · Viewed 16.2k times · Source
Table 1 - leads
column 1 - lead_source_description

Table 2 - leads_cstm
column 2 -referrer_c 

I am trying to copy values from table2.column2 to table1.column1 using the following query

INSERT INTO leads (`lead_source_description`)
SELECT `referrer__c`
FROM leads_cstm

I know it is quiet a simple task to do and has been asked already . But I am getting the following error.

#1062 - Duplicate entry '' for key 'PRIMARY'

Answer

Aswani Madhavan picture Aswani Madhavan · Oct 15, 2017
INSERT INTO leads (`lead_source_description`)
SELECT DISTINCT `referrer__c` FROM leads_cstm