Disk full (/var/tmp/#sql_4ef_0); waiting for someone to free some space... SELECT p.*, MAX(pd.discount) discount, b.image brandImage, b.name brandName, c.googleCategoryID FROM products p LEFT JOIN brands b ON (p.brand = b.id) LEFT JOIN products_categories pc ON (p.id = pc.product) LEFT JOIN categories c ON (pc.category = c.id) LEFT JOIN types t ON (p.type = t.id) LEFT JOIN products_discounts pd ON (p.id = pd.product AND pd.status = 'active' AND 1749301952 > dateFrom AND 1749301952 < IF(dateTo > 0, dateTo, 2147483647)) WHERE discount > 0 AND p.status = 'active' GROUP BY p.id