我有一个帖子回复表,我现在用同一个用户对同一个帖子进行多次回复操作。然后我想在用户的“我参与的帖子”里看到用户参与的帖子。
根据用户的ID进行选取:
SELECT wb_bbsReply.replyTime, wb_bbsReply.postId, wb_bbsPost.postTitle
FROM wb_bbsReply INNER JOIN
wb_bbsPost ON wb_bbsReply.postId = wb_bbsPost.postId
where wb_bbsReply.userId=@userid
但是这样选取出来的数据是同一个用户对一个贴子的多次回复的数据表。
有没有办法选取出即使当同一个用户对一个贴子的多次回复我也只选取最近的一条数据,而不是用户对帖子的所有回复?
根据用户的ID进行选取:
SELECT wb_bbsReply.replyTime, wb_bbsReply.postId, wb_bbsPost.postTitle
FROM wb_bbsReply INNER JOIN
wb_bbsPost ON wb_bbsReply.postId = wb_bbsPost.postId
where wb_bbsReply.userId=@userid
但是这样选取出来的数据是同一个用户对一个贴子的多次回复的数据表。
有没有办法选取出即使当同一个用户对一个贴子的多次回复我也只选取最近的一条数据,而不是用户对帖子的所有回复?
FROM wb_bbsReply INNER JOIN
wb_bbsPost ON wb_bbsReply.postId = wb_bbsPost.postId
where wb_bbsReply.userId=@userid
order by wb_bbsReply.replyTime desc
FROM wb_bbsReply INNER JOIN
wb_bbsPost ON wb_bbsReply.postId = wb_bbsPost.postId
where wb_bbsReply.userId=@userid
group by wb_bbsPost.postTitle
可能我的问题也问的不准确。
问题:一个用户参与了多个帖子。里面有些帖子是多次回复的。如果用我上面那种SQL语句,可以查询到。但是却不能限制多次回复的帖子只出现一次。
我说怎么在另一个贴中怎么都找不到。如果是 3楼哥们发的,那太巧合了。
希望是 CSDN的问题,不是巧合
wb_bbsPost 是BBS的贴子列表?如果是就可以这样试试Select wb_bbsPost.postTitle,
replyTime=(select top 1 replyTime From wb_bbsReply Where wb_bbsReply.postId = wb_bbsPost.postId Order By wb_bbsReply.repluTime Desc ),
wb_bbsPost.postId
From wb_bbsPost
Where exists (Select * From wb_bbsReply
Where wb_bbsReply.postId = wb_bbsPost.postId
and wb_bbsReply.userId=@userid
)凭空写的,不知道有没语法错误