0

以下查询为每次出现 recipecomments.RecipeID 带来一条记录,我只想为每个 recipeID 带来一条记录,按 recipeid 分组似乎不起作用

SELECT recipecomments.RecipeID
      ,recipecomments.CommentID 
      ,recipes.RecipeID
      ,recipes.Name
      ,recipes.CategoryID
      ,recipes.RatingTotal
      ,recipes.ImageMed
FROM recipecomments 
     JOIN recipes ON recipecomments.RecipeID = recipes.RecipeID                 
ORDER BY recipecomments.CommentID
4

1 回答 1

1

如果您按recipid 分组,您需要决定要显示哪个CommentID。从你的语法来看,我猜是最高的。

 SELECT 
      recipecomments.RecipeID,
      MAX(recipecomments.CommentID),
      recipes.RecipeID,
      recipes.Name, 
      recipes.CategoryID,
      recipes.RatingTotal,
      recipes.ImageMed
 FROM recipecomments   
                JOIN recipes ON recipecomments.RecipeID = recipes.RecipeID 
 group by 
      recipecomments.RecipeID,
      recipes.RecipeID,
      recipes.Name, 
      recipes.CategoryID,
      recipes.RatingTotal,
      recipes.ImageMed
于 2012-08-20T13:55:14.653 回答