I am using SQL Server Compact 4.0 and am trying to get one query to return a single record with a column Alarm
based on the maximum identity when another column Cleared
is NULL
.
This works:
SELECT Id, Alarm
FROM Alarm_History
WHERE Cleared IS NULL
Giving me half the answer. The problem is that it returns several records.
This also works:
SELECT MAX(Id)
FROM Alarm_History
WHERE Cleared IS NULL
And it gives me the other half of the answer, but I can't get the value "Alarm" that I am looking for.
But they DON'T work together as in:
SELECT Id, Alarm
FROM Alarm_History
WHERE Cleared IS NULL AND Id = MAX(Id)
OR
SELECT MAX(Id), Alarm
FROM Alarm_History
WHERE Cleared IS NULL
With the queries above I can do two consecutive queries to get the result back, but I don't think this is very efficient. Is there a way to do this in one trip to the database?
Thanks Jeff