我有以下查询我要火:SQL查询 - 结合DISTINCT和TOP?
SELECT DISTINCT TOP(5) fp.PostId FROM dbForumPosts fp
LEFT JOIN dbForumEntry fe ON fp.PostId = fe.PostId
Order by fe.Datemade DESC
然而,当我火了,我得到的错误:
Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
我试图更改查询,所以它使用GROUP BY代替,但我有以下问题:
Msg 8127, Level 16, State 1, Line 4
Column "dbForumEntry.Datemade" is invalid in the ORDER BY clause because it is not contained in either an aggregate function or the GROUP BY clause.
我想要什么:
认为这是一个论坛。有帖子(dbForumPosts)和条目(dbForumEntry)。这里有0个很多条目。
我想是与最近的活动(在最新更新的条目职位)的get职位。
您正在使用哪个数据库管理系统? –
的SQL Server 2008 R2(MSSQL) –
还能有'Datemade'每'PostId'不止一个?如果是的话,哪一个用于订购目的? –