0

I can't quite get this query to work how I want it to.

IF(h.STATUS="On-Login-Screen") OR (h.STATUS="IE-Window-Missing") 
SELECT MAX(h.TIME) limit 1 AS LastDown

Essentially I want to check the last time h.Status equaled one of the above things, and get the most recent time when it does equal one of those things as a variable named LastDown.

1 Answer 1

1

Try this:

SELECT MAX(h.TIME) AS LastDown
FROM TABLENAME
WHERE (h.STATUS='On-Login-Screen') OR (h.STATUS='IE-Window-Missing') 
--limit 1 

Or

SELECT MAX(h.TIME) AS LastDown
FROM TABLENAME
WHERE h.STATUS IN ('On-Login-Screen','IE-Window-Missing') 
3
  • The second example is better, as it will use an index, if found. Commented May 7, 2013 at 19:56
  • Is there a way to do this for each ID?
    – A_Elric
    Commented May 7, 2013 at 19:57
  • @Damien.Bell what do you meant by each ID? can you post example?
    – rs.
    Commented May 7, 2013 at 20:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.