: SELECT * FROM products LEFT OUTER JOIN product_categories ON products.product_category_id = product_categories.product_category_id WHERE products.product_company_id='29' GROUP BY products.product_category_id ORDER BY SUM(product_in_stock) DESC, product_categories.product_category_parent, product_categories.product_category_name;.