select name, cnt from ( select tbl, count(*) as cnt from stv_blocklist where tbl in ( select id from stv_tbl_perm) group by tbl ) block_list inner join stv_tbl_perm on block_list.tbl=stv_tbl_perm.id group by tbl, stv_tbl_perm.name, block_list.cnt order by cnt; Register as a new user and use Qiita more conveniently You get articles that match your needsYou can efficiently read back useful informati