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 1749301748 > dateFrom AND 1749301748 < IF(dateTo > 0, dateTo, 2147483647)) WHERE pc.category = '1' AND p.id <> 64 AND p.status = 'active' GROUP BY p.id ORDER BY p.views LIMIT 10