select t1.*, count(distinct name) from table t1
left join table2 t2 on t2.t1_id = t1.id
group by name
order by t2.order_colum
limit 0,1000