sort by plus cards+solution+sql2
select c.name, coalesce(count,0) as sort_field
from cards c
left join (
select z.id, count(*) as count
from cards z
join wiki_references r on r.referenced_card_id = z.id
where r.card_id in (
select id from cards tx
where tx.tag_id in
(select id from cards txx where txx.key = 'territory')
and tx.trunk_id in
(select id from cards txx where txx.extension_type = 'User')
)
group by z.id
) s
on c.id = s.id
where c.type='Zone'
and c.trash is false
order by sort_field desc
limit 10;