Hi all,
I have a table which contains multiple records for the same room, it contains history for each time the room is audited. Each time the room is audited the date is written to the "CompStamp" field in the format "2016-03-01". A filed named SeqID1307 is alos written to with the temperature of water, SeqId1303 is a decimal type field. So it could contain 20, 24.3 or any variant of a decimal number.
Now I am trying to extract records from the table where the variable "CompStamp" has the latest date.
I have tried the following:
Query 1.
SELECT UniqueID, SeqID1307, Room, CompStamp
FROM ROSE_Hist
WHERE SeqID1307 > 20 AND CompStamp in (SELECT MAX(CompStamp) from ROSE_Hist GROUP BY Room
This returns 3 records.
If I use Navicat and run:
Query 2.
SELECT UniqueID, Room, MAX(CompStamp)
FROM ROSE_Hist
WHERE SeqID1307 > 20 GROUP BY Room ORDER BY Room ASC
This returns 303 records.
When I look at the 303 records the SeqID1307 fields they contain the number 20 or more.
I think my question is, which Query should i be using to reurn the correct records, Query 1 or Query 2 or am I doing this completely wrong.
Many thanks in advance for your time.
Cheers.