At our television station we have a schedule of shows that need to be aired (stationschedule) and shows that have aired confirmed by our on air system (asrunlogs).
What I'd like to do is compare both tables against eachother to see if there are any major differences. Both tables have two similar fields showid, airtime as below:
Stationschedule
-----------------
ShowID
Show_Name
Airtime
Asrunlogs
-----------------
ShowID
Airtime
However If I pull a sample of the asrunlogs for ShowID LOC-3305:
SELECT ShowID, airtime
FROM asrunlogs
WHERE ShowID = "LOC-3305"
AND airtime LIKE "2008-06-26%"
ShowID Airtime
LOC-3305 2008-06-26 12:31:30
LOC-3305 2008-06-26 16:02:29
LOC-3305 2008-06-26 17:31:30
Then I do the same from stationschedule for same id LOC-3305:
SELECT ShowID, airtime
FROM stationschedule
WHERE ShowID = "LOC-3305"
AND airtime LIKE "2008-06-26%"
ShowID Airtime
LOC-3305 2008-06-26 12:31:30
LOC-3305 2008-06-26 16:02:30 ** difference 1 second
LOC-3305 2008-06-26 17:41:30 ** difference 10 minutes
As you can see one of the times has a difference of 10 minutes. What I'd like to do is query the rows that have a time difference greater than 30 seconds when comparing the two tables.
SELECT a.airtime, a.ShowID
FROM asrunlogs a
WHERE a.Airtime LIKE "2008-06-26%"
AND a.ShowID = "LOC-3305"
AND a.Airtime NOT
IN (SELECT b.Airtime
FROM stationschedule b
WHERE TIME_TO_SEC( TIMEDIFF( RIGHT( a.Airtime, 9 ) , RIGHT( b.Airtime, 8 ) ) ) > 30)
Any Idea whats wrong with my syntax or is there an easier way of doing this ?