上午
我需要删除基于3个字段匹配的重复项。我根据一个标准编写了一行代码,但需要添加更多代码。
我的代码:
DoCmd.RunSQL ("DELETE tbl_Added.*, tbl_Added.[NUM_CUST]FROM tbl_Added WHERE (((tbl_Added.[NUM_CUST]) In (Select tbl_Removed.[NUM_CUST] from tbl_Removed)));")
我想添加的额外字段名称是: - NeedType - CrackID
感谢任何帮助
更新 我也在尝试下面的VBA无济于事
DoCmd.RunSQL ("DELETE tbl_Added.*, tbl_Added.[NUM_CUST],tbl_Added.[ID_CRAC] FROM tbl_Added WHERE (((tbl_Added.[NUM_CUST],tbl_Added.[ID_CRAC]) In (Select tbl_Removed.[NUM_CUST], tbl_Removed.[ID_CRAC] from tbl_Removed)));")
答案 0 :(得分:1)
以下SQL将返回基于您提到的三个字段相等的重复记录的NUM_CUST
字段:
SELECT NUM_CUST
FROM tbl_added
GROUP BY NUM_CUST, NEEDTYPE, CRACKID
HAVING Count(NUM_CUST) > 1
从这里开始,您需要决定是否要从表中删除所有此类记录,或仅删除重复记录,保留每个记录的单个实例。