SELECT `Brands`.* FROM `Brands` INNER JOIN `CatItems` ON `Brands`.`__id` = `CatItems`.`Brand` WHERE `CatItems`.`Category` IN (52,368,369,370,371,373,374,3453,141,325,378,1556,2998,2999,4452,2997,375,376,377,3084,3342,3634,3635,3636,3637,3638,3639,3709,5118,4899,4901,5364,5566,5742,5741,5743,5745,5746,5949,5943,5944,5945,5946,20) AND `CatItems`.`Active` = 1 GROUP BY `Brands`.`__id` ORDER BY `Brands`.`CustomOrder`