You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'AND productos.stock_global > 0 AND familias.activo = 1 GROUP BY productos.id OR' at line 1