如何在ms访问中使用DISTINCT?

时间:2015-04-23 14:30:15

标签: sql ms-access ms-access-2007 ms-access-2010 ms-access-2013

我有以下查询:

SELECT DISTINCT AwardDescriptions.aID, CostCentres.cCC 
FROM  AwardDescriptions 
INNER JOIN CostCentres ON AwardDescriptions.aID = CostCentres.cNumber 
ORDER BY CostCentres.cCC;

出于某种原因,当我运行查询时,它仍然显示所有重复的值。 有什么建议吗?

1 个答案:

答案 0 :(得分:1)

您可以使用group by并获取最小值或最大值:

SELECT MAX(AwardDescriptions.aID) as aID, CostCentres.cCC 
FROM  AwardDescriptions INNER JOIN
      CostCentres
      ON AwardDescriptions.aID = CostCentres.cNumber 
GROUP BY CostCentres.cCC
ORDER BY CostCentres.cCC;