SQL Server:根据多对n:m关系中的最新id进行选择
我需要做的是选择评论详细信息以及对评论采取的最后操作;我有 3 个表:
Comment
CommentID, commentText, userID, date_posted
Action
ActionID, action_taken,userID,date_actioned
和 CommentJoinAction
id,ActionID,CommentID
可以有一个评论,但该评论可以有多个操作。
我的 SQL 看起来像这样:
Select /*snip comment details and such*/
From Comment
Inner Join (select max(actionid) from commentjoinaction) as cja on /*blah cause you know from reading this, it won't work*/
那么我可以做什么,以便我始终为评论获取最新的 commentAction 。
非常感谢
What i need to do is select the comment details and the last action taken on the comment; I have 3 tables:
Comment
CommentID, commentText, userID, date_posted
Action
ActionID, action_taken,userID,date_actioned
and CommentJoinAction
id,ActionID,CommentID
There can be one comment, but many actions on the comment.
my SQL is looking something like:
Select /*snip comment details and such*/
From Comment
Inner Join (select max(actionid) from commentjoinaction) as cja on /*blah cause you know from reading this, it won't work*/
So what is it that I can do so that I always pick up the latest commentAction for the comments.
many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是您要找的吗?
Is this what you are looking for?
如果您只想要 actionID
或者如果您想要所有 Action 字段:
If you just want the actionID
Or if you want all the Action fields: