QUERY: SELECT `brand`.* FROM `brand` INNER JOIN `product` ON `product`.`BrandID` = `brand`.`ID` INNER JOIN `invoice_detail` ON `invoice_detail`.`ProductID` = `product`.`ID` ORDER BY COUNT(`product`.`BrandID`) DESC
ERROR: Expression #1 of ORDER BY contains aggregate function and applies to the result of a non-aggregated query