如何在MS Access中为重复记录返回其他列及其值?

时间:2014-04-21 19:27:36

标签: sql ms-access

目前,下面的查询会根据其名称返回重复记录列表,但是我无法包含可能具有不同值的其他列。

有没有办法实现这个目标?例如,我可以拥有一个具有相同名称但由其他人创作或创建的客户记录。我需要知道作者是谁,以便我们可以优先考虑哪些记录可以删除。

SELECT o.ObjType, o.name, COUNT(o.Name) as NameCount, o.Author
FROM customer as o
GROUP BY o.ObjType,o.name, o.Author
HAVING (COUNT(o.name)>1) 
ORDER BY o.name ASC

1 个答案:

答案 0 :(得分:0)

您可以通过加入原始数据来执行此操作:

SELECT c.*
FROM (SELECT o.ObjType, o.[name], COUNT(o.[Name]) as NameCount, o.Author
      FROM customer as o
      GROUP BY o.ObjType, o.[name], o.Author
      HAVING COUNT(o.[name]) > 1
     ) as dups inner join
     customer as c
     on c.ObjType = dups.ObjType and c.[name] = dups.[name] and c.Author = dups.Author
ORDER BY c.ObjType, c.[name], c.Author;