SELECT *
FROM
(
SELECT 
	Active.id As NumberID,
	Active.eventtime As 'Start Timestamp', 
	IFNULL(Clear.eventtime,'') as 'End Timestamp',
	IFNULL(CONVERT(SEC_TO_TIME(Clear.eventtime - Active.eventtime),VARCHAR(20)),(SEC_TO_TIME(NOW()-Active.eventtime))) as Duration,
	Class.strvalue As Class,
	Location.strvalue As Area,
	Description.strvalue As Description,
	Tag.strvalue As Tag,
	alarm_events.eventtype as eventtype
FROM alarm_events
LEFT OUTER JOIN alarm_events as Active ON alarm_events.eventid = Active.eventid AND (Active.eventtype = 0)
LEFT OUTER JOIN alarm_events as Clear ON alarm_events.eventid = Clear.eventid AND (Clear.eventtype = 1)
LEFT OUTER JOIN alarm_event_data as Class ON alarm_events.id = Class.id AND (Class.propname = "Class")
LEFT OUTER JOIN alarm_event_data as Location ON alarm_events.id = Location.id AND (Location.propname = "Area")
LEFT OUTER JOIN alarm_event_data as Description ON alarm_events.id = Description.id AND (Description.propname = "Description")
LEFT OUTER JOIN alarm_event_data as Tag ON alarm_events.id = Tag.id AND (Tag.propname = "Tag")
WHERE (alarm_events.eventtime BETWEEN :starttime AND :endtime)
) t1
WHERE t1.eventtype = 0 and t1.Class = 'Error' or t1.Class = :warning or t1.Class = :message