Question : Select Query to identify when a customer ID exists during the same time period Part 2

I have a list of events that occur at specific times between two customers. I need to isolate any instance where the same person is in two seperate locations at the same time.  For example I have simplified the schema.

EventID        Cust1        Cust2          LocationID         EventTime
------------------------------------------------------------------------------------
1                     1                 2                  1                  9/1/2010 8:00
2                     1                 3                  1                  9/1/2010 9:00
3                     4                 1                  3                  9/1/2010 8:00
4                     1                 5                  3                  9/1/2010 9:00
5                     2                 5                  3                  9/1/2010 10:00
6                     1                 1                  2                  9/1/2010 11:00
In the above instance I need a query that returns rows 1,2, 3 ,4 and 6 because customer 1 can't be at location 1 and location 3 at the same times.  The following code block works perfectly with the exception of when cust1 and cust2 are the same person.  The following query only returns rows 1,2,3 and 4. (missing row 6)

1:
2:
3:
4:
5:
SELECT t1.*
FROM tblEvents t1 INNER JOIN
    tblEvents t2 ON t1.EventID <> t2.EventID AND t1.EventTime = t2.EventTime AND
    (t1.Cust1 = t2.Cust1 OR t1.Cust1 = t2.Cust2 OR t1.Cust2 = t2.Cust1 OR t2.Cust1 = t2.Cust2)


Thanks,

Answer : Select Query to identify when a customer ID exists during the same time period Part 2

You could simply try a UNION statement.

SELECT t1.* FROM tblEvents t1 INNER JOIN
tblEvents t2 ON t1.EventID<>t2.EventID AND t1.EventTime=t2.EventTime AND t1.LocationID<>t2.LocationID AND (t1.Cust1 = t2.Cust1 OR t1.Cust1 = t2.Cust2 OR t1.Cust2 = t2.Cust1 OR t2.Cust1 = t2.Cust2)
UNION ALL
SELECT * FROM tblEvents WHERE Cust1=Cust2

If you want it ordered, you can add: ORDER BY 1
Random Solutions  
 
programming4us programming4us