SELECT replace(concat(shopcoins_name.name, " ", yearstart), '/',' ') as title, materialtype , 1 as stype, shopcoins_name.name, nominal_id, yearstart, count(*) as countcoins, count(distinct(catalognew.`group`)) as countgroup, catalognew.`group`, g.name as gname FROM `catalognew`, shopcoins_name, `group` as g where continent_id='1877' and (g.groupparent<>'1892') and materialtype='2' and catalognew.agreement >= 0 and yearstart>1000 and catalognew.nominal_id = shopcoins_name.id and nominal_id not in (23028, 7560, 1559, 1122) and catalognew.`group` = g.`group` group by concat(nominal_id, " ", yearstart) order by shopcoins_name.name, yearstart desc