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 productos.controla_stock = 1 AND productos.stock > 0 GROUP BY marcas.id, ...' at line 1