SELECT SQL_CALC_FOUND_ROWS t.* FROM( SELECT image.path, (SELECT MAX(timestamp) FROM product_attribute WHERE product.id=product_attribute.product_id AND product_attribute.timestamp > 0) AS expires, brand.brand_name AS brand_name, brand.show_on_auckscuba, product.* FROM product JOIN brand ON brand.id=product.brand_id LEFT JOIN image ON product.id=image.product_id AND image.position=0 WHERE brand.brand_name='oceanic' AND brand.id=product.brand_id AND product.status=1 AND brand.show_on_auckscuba=1 AND (product.enable_stock_control=0 OR product.current_stock > 0 OR (product.enable_stock_control=1 AND (product.display_stock_sold=0 OR ( product.display_stock_sold=1 AND product.last_sold > 1538834513 )) ) ) GROUP BY product.id ORDER BY brand.brand_name ASC ) t WHERE t.expires IS NULL OR t.expires > 1540044113 ORDER BY t.product_name ASC, brand.brand_name ASC LIMIT 0,100

Unknown column 'brand.brand_name' in 'order clause'