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 foto.deleted IS NULL AND a.status!=0 GROUP BY foto.sku_group, foto.id_color,' at line 3 :: QUERY => SELECT foto.* FROM `isa_articoli_foto` AS foto INNER JOIN `isa_articoli` AS a ON (foto.sku_group = a.sku_group AND foto.id_color = a.id_color) WHERE foto.sku_group = '' AND foto.id_color = AND foto.deleted IS NULL AND a.status!=0 GROUP BY foto.sku_group, foto.id_color, foto.tipo ORDER BY foto.tipo ASC