从仅插入的另一个表插入无重复项

时间:2013-04-02 07:14:00

标签: mysql sql-update no-duplicates

我已经和他斗争了好几个小时了。我需要从多个表构建一个主表(糟糕的设计,我知道。)我写了这段代码:

INSERT INTO amdashboard
(DashboardFirst, DashboardLast, charlotteorg, charlotteAdd1, charlotteCity, charlotteState, charlotteZip, charlottey2007, charlottey2008, charlottey2009,charlottey2010, charlotteY2011, charlotteY2012)
select Firstname, lastname, org, add1, city, state, zip, y2007, y2008, y2009, y2010, y2011, y2012
from CharlotteClean
ON DUPLICATE KEY UPDATE 
amdashboard.DashboardFirst = CharlotteClean.Firstname,
amdashboard.DashboardLast = CharlotteClean.Lastname,
amdashboard.Charlotteorg = CharlotteClean.org,
amdashboard.Charlotteadd1 = CharlotteClean.add1,
amdashboard.Charlottecity = CharlotteClean.city,
amdashboard.Charlottestate = CharlotteClean.state,
amdashboard.Charlottezip = CharlotteClean.zip,
amdashboard.Charlottey2007 = CharlotteClean.y2007,
amdashboard.Charlottey2008 = CharlotteClean.y2008,
amdashboard.Charlottey2009 = CharlotteClean.y2009,
amdashboard.Charlottey2010 = CharlotteClean.y2010,
amdashboard.Charlottey2011 = CharlotteClean.y2011,
amdashboard.Charlottey2012 = CharlotteClean.y2012;

我已将DashboardFirst和DashboardLast作为组合键。但每当我运行它时,它只会插入,永远不会更新,我知道有些记录应该更新。

有什么想法吗?

0 个答案:

没有答案