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:

http://img189.imageshack.us/img189/6872/26352213.png

How can i query those results to obtain this:

http://img249.imageshack.us/img249/8498/10059621.png


Please, be aware that i would like the last report ID, not the last date. Can anyone help me out?

Best Regards

if you need the last reportid how come you have reportid 86 in your example picture? because if reportid is integer in increment by one you need something like this.

SELECT TOP 1 IDREPORT
FROM Report
ORDER BY IDREPORT DESC

but again i dont know why do you have two results.

Hi jbisono,

You did not understand the problem.

Hi want ALL the last reports for respective hardware ID, not just the last one

oh ok well the easiest way is use group

SELECT MAX(IDREPORT) AS IDREPORT, IDHARDWARE
FROM REPORT
GROUP BY IDHARDWARE
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.