SELECT p.brand AS brand_id, b.Name AS brand_name, COUNT(DISTINCT p.ido) AS count FROM products p JOIN categories_status cs ON p.ido=cs.product_id LEFT JOIN products_attributes pa ON pa.pr_item_code=p.item_code AND pa.avl > 0 AND status > 0 JOIN brands b ON b.ido=p.brand WHERE p.is_trouble = 0 AND p.pos = 1 AND p.active = 1 AND p.in_stock =1 AND pa.avl > 0 AND pa.status > 0 GROUP BY p.brand ORDER BY count DESC LIMIT 6 - Can't create/write to file '/tmp/MYD4MH48' (Errcode: 28)