DB (2006) MySQL server has gone away : select v.* from videos v inner join categories c on (v.id_category=c.id) where v.is_active=1 and (v.flag_video_file=1) and v.is_featured=1 and c.is_active=1 and ((SELECT count(*) from categories c2 where c2.id=c.idParent and c2.is_active=1)>0) and ((v.id_category=1184)) and (v.id_sector=250) group by v.id order by RAND() limit 13