Errormessage: SELECT DISTINCT a.cat_id, b.name, b.url FROM (SELECT distinct b.cat_id , count(b.cat_id) tot FROM comclass a JOIN comclass b on a.comp_id = b.comp_id where a.cat_id = 10843 AND b.cat_id != 0 GROUP BY b.cat_id HAVING tot > 2 ORDER BY tot desc LIMIT 50 ) a JOIN comclass c ON c.cat_id = a.cat_id JOIN categories b ON b.id = a.cat_id WHERE c.city_id = 11294 LIMIT 10 MySQL server has gone away