Error: SELECT,, i.alt_name, b.title, l.address, l.postcode, city_name, c.code , c.url, count( totrev, avg(rating) rate, photo_id,, l.lng, t.photo_id g_photo_id, i.alt_name, z.radius FROM company b JOIN company_premium z on z.company_id = JOIN subscriptions s on = z.subscription_id LEFT JOIN company_city_cat a USING (company_id) LEFT JOIN company_location l USING (company_id) LEFT JOIN company_photo t USING (company_id) LEFT JOIN company_info_2 i USING (company_id) LEFT JOIN city c on a.city_id = LEFT JOIN review r on r.company_id = AND r.approved > 0 LEFT JOIN photo p on p.company_id = AND logo = 1 WHERE = 1 AND a.`cat_id` IN ( , 1589 ) GROUP by a.company_id ORDER BY RAND() LIMIT 5 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near ' 1589 ) GROUP by a.company_id ORDER BY RAND() LIMI' at line 15