Ho la seguente interrogazione voglio il fuoco:SQL Query - Combina DISTINCT e TOP?
SELECT DISTINCT TOP(5) fp.PostId FROM dbForumPosts fp
LEFT JOIN dbForumEntry fe ON fp.PostId = fe.PostId
Order by fe.Datemade DESC
Tuttavia, quando ho fuoco, ottengo l'errore:
Msg 145, Level 15, State 1, Line 1
ORDER BY items must appear in the select list if SELECT DISTINCT is specified.
ho cercato di modificare la query, quindi ha usato GROUP BY invece, ma poi ho il seguente problema:
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.
cosa voglio:
0.123.Pensa a questo come a un forum. Ci sono post (dbForumPosts) e voci (dbForumEntry). Ci sono 0-molte voci pr post.
Quello che voglio è ottenere i post con l'attività più recente (post con le ultime voci aggiornate in).
Quale DBMS stai utilizzando? –
SQL Server 2008 R2 (MSSQL) –
Possono esserci più di un 'Datemade' per' PostId'? Se sì quale usare per gli ordini? –