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 'AND photos_id IN (12,14,23,24,25,26,27,35)' at line 1 SELECT COUNT(*) AS pocet FROM product_variant WHERE product_id = AND photos_id IN (12,14,23,24,25,26,27,35)