Order the categorys after most threads
I have two tables, one for categories
and one for threads
.
My cats-table:
- idCats
- name
- rules开发者_如何学运维
My threads-table:
- idThreads
- title
- content
- category
- creator
- votes
- created
The category in my threads-table contains the id of the category.
The following query should give you a list of category names and their corresponding thread counts in descending order:
select
c.name,
COUNT(*) as cnt
from
cats c
left join threads t
on c.idCats = t.category
group by
c.name
order by
cnt desc
精彩评论