SELECT o.ID, o.name, o.model, o.picture, o.param, params.all_params_props FROM wp_offers o LEFT JOIN ( SELECT offer_id, COUNT(id_param) AS param_count, GROUP_CONCAT(CONCAT(id_param, ':', id_prop) ORDER BY id_param ASC SEPARATOR ',') AS all_params_props FROM wp_goods_pp WHERE good_id = '590529' GROUP BY offer_id ) AS params ON o.ID = params.offer_id WHERE o.good_id = '590529' ORDER BY params.param_count DESC LIMIT 24;