I've got the query below that I'm using and it's REALLY slow. I've recently learned that a left join would be a lot faster but I don't know how to convert it into a left join. Anyone have any ideas? $PingTrackerSQL = "Select KeywordID from LG.PingTracker where DatePinged > Date_Sub(CurDate(), Interval 7 Day)"; $RKSQL = "select ID from B.Keywords where RootKeywordID = $RootKeywordID and ID not in ($PingTrackerSQL) order by rand() limit 1"; Code (markup):
It looks like you can do a regular inner join and set criteria to <= instead of NOT IN > Something like this: $RKSQL="select ID from B.Keywords KW INNER JOIN LG.PingTracker PT ON KW.ID=PT.RootKeywordID where KW.RootKeywordID = $RootKeywordID and PT.DatePinged <= Date_Sub(CurDate(), Interval 7 Day) order by rand() limit 1" Code (markup):