删除一列重复的行(不是'不同')

时间:2013-03-25 10:35:17

标签: sql ms-access group-by distinct

我正在使用访问权限,而我正在尝试编写一个查询,该查询将删除一列的重复项。这是我到目前为止的查询:

SELECT
  Drawings.DrawingID,
  Players.NumOfGuessedAPainting,
  Players.NumOfGuessedBPainting,
  Players.NumOfGuessedCPainting,
  Words.Word
FROM Words INNER JOIN
    (Players INNER JOIN
    (Drawings INNER JOIN
     PlayersAndWords 
       ON Drawings.DrawingID = PlayersAndWords.DrawingID)
       ON Players.PlayerID = PlayersAndWords.DrawingPlayerID)
       ON Words.WordID = PlayersAndWords.WordID 
WHERE ((Words.Word)='" + w + "')
ORDER BY (Players.NumOfGuessedAPainting
         +Players.NumOfGuessedBPainting * 2
         +Players.NumOfGuessedCPainting *3 ) DESC

Drawings.DrawingID可能是重复的,我希望查询只返回每个Drawings.DrawingID的一行。 “不同”在这里不起作用。我读过group by可能会有所帮助,但我无法弄清楚如何...... 你可以帮帮我吗?

提前致谢。

1 个答案:

答案 0 :(得分:0)

只需在ORDER BY行

之前加上这些内容
GROUP BY
    Drawings.DrawingID,
    Players.NumOfGuessedAPainting,
    Players.NumOfGuessedBPainting,
    Players.NumOfGuessedCPainting,
    Words.Word

编辑。