Errormessage: SELECT DISTINCT a.cat_id, b.name, b.url, tot 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 = 12572 AND b.cat_id != 12572 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 = 43598 LIMIT 5 MySQL server has gone away