Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Hi there!I´m with some difficult to do this query.I have this:
SELECT IDReport AS [ID Report], IDHardware AS [ID Hardware], DataHoraReport AS [Último Report], Versao AS Versão, DataInstalacao AS Instalação, DataUltimaActualizacao AS [Última Actualização]FROM Report
in which result this:How can i query those results to obtain this:Please, be aware that i would like the last report ID, not the last date.Can anyone help me out?Best Regards
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts
Posted - 2010-06-08 : 07:22:59
SELECT IDReport AS [ID Report], IDHardware AS [ID Hardware], DataHoraReport AS [Último Report], Versao AS Versão, DataInstalacao AS Instalação,DataUltimaActualizacao AS [Última Actualização]FROM Report r inner join (Select max(IDReport) as IDReport,IDHardware from Report group by IDHardware )r1on r.IDReport =r1.IDReportSenthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceledhttp://senthilnagore.blogspot.com/
pee2002
Starting Member
16 Posts
Posted - 2010-06-08 : 07:31:33
That solution gives me the follow error:
Msg 8120, Level 16, State 1, Line 7Column 'Report.IDHardware' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Msg 209, Level 16, State 1, Line 5Ambiguous column name 'IDReport'.Msg 209, Level 16, State 1, Line 5Ambiguous column name 'IDHardware'.