0

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

2
Contributors
3
Replies
4
Views
7 Years
Discussion Span
Last Post by jbisono
0

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.

0

Hi jbisono,

You did not understand the problem.

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

0

oh ok well the easiest way is use group

SELECT MAX(IDREPORT) AS IDREPORT, IDHARDWARE
FROM REPORT
GROUP BY IDHARDWARE
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.