Query to find instances of two types of events occurring more than one second apart
I don't think your code is correct.

select top 1, without any kind of order by clause selects an essentially random record from a table, so unless you know that there can be only one event with the right EventTypeId you may be missing event combinations that are relevant.

If I understand the problem correctly, I think you need something more like this:

select A.BusinessObjectId from
( select BusinessObjectId, min(DateEvent) as min, max(DateEvent) as max 
  from CustomEvent where EventTypeId = 11
  group by BusinessObjectId 
) as A
inner join 
( select BusinessObjectId, min(DateEvent) as min, max(DateEvent) as max 
  from CustomEvent where EventTypeId = 10
  group by BusinessObjectId 
) as B on A.BusinessObjectId = B.BusinessObjectId
where datediff( second, A.min, B.max ) &gt; 1 or datediff( second, B.min, A.max ) &gt; 1
group by A.BusinessObjectId


I have not included the six month restriction.