I have the following query:
select * from winners
join profiles on winners.subscriber_id = profiles.subscriber_id
join comments on comments.profile_id = profiles.vanity
join videos on winners.subscriber_id = videos.subscriber_id
join photos on winners.subscriber_id = photos.subscriber_id
where winners.round_id >= 4 AND winners.active = true
AND (comments.created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR) OR videos.created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR) OR photos.created_at > DATE_SUB( NOW(), INTERVAL 24 HOUR)) AND comments.parent_id = 0;
This query runs on a cron job that will pull the latest information for the past 24 hours for each winner and then will email each of the winners fans with the latest info.
The issues I am running into is that the query is pulling back false positives in that if a comment on a video happened in the past 24 hours then it pulls back the video and the comment. Is there anyway to limit to get EVERYTHING that has happened in the past 24 hours?
I would move the 24 hour check to the join. That way we only join on items which have been updated recently.