This query pulls from two separate tables. The video_thumb_chosen has a thumbcolumn that needs where the mode value needs to be selected.
$query = "SELECT DISTINCT videos.VIDEOID,
videos.title,
(
select video_thumb_chosen.thumb
from video_thumb_chosen
where video_thumb_chosen.videoid = videos.VIDEOID
group by video_thumb_chosen.thumb
order by count(video_thumb_chosen.thumb) desc limit 1
) as thumb,
videos.rating,
videos.runtime,
videos.viewcount,
videos.public,
videos.time_added,
videos.HD
FROM videos,video_thumb_chosen
WHERE videos.active='1'
&& videos.tube=0
&& videos.categories <> 7
ORDER BY videos.last_viewed desc limit $config[max_viewing_now]";
Removing the cross join in the
fromclause would help:You are not using video_thumb_chosen in the outer query, so there is no reason to include it.
There may be other optimizations as well.
Given what you are doing in MySQL, that will probably fix the problem. Here is the query: