Query failed : SELECT r.*, f.`id` AS `fabric_id`, f.`name` AS `name`, f.`pattern`, f.`width`, o.`name` AS `colour`, f.`composition`, s.`name` AS `suitability`, IF(o.`hidden` + c.`hidden` + f.`hidden` + c.`shop` = 0, c.`seolink`, NULL) AS `seolink`, IF(COUNT(t.`id`) > 0, 1, 0) AS `purchased`, f.`img_alt`, FROM (`remnants` r, `colours` c, `fabrics` f, `options` o, `suitability` s) LEFT JOIN `transactions_products` tp ON tp.`product` = r.`id` AND tp.`table` = 'remnants' LEFT JOIN `transactions` t ON t.`id` = tp.`transaction` AND t.`result` = 'OK' WHERE c.`id` = r.`fabric` AND f.`id` = c.`fabric` AND o.`id` = c.`colour` AND s.`id` = f.`suitability` AND (r.`id` = '' OR r.`seolink` = 'red-casey-remnant') AND r.`hidden` = 0 GROUP BY r.`id` HAVING COUNT(t.`id`) = 0 at line 45