SQL return name of most popular / unpopular category
mysql, sql
Solution
Something like this should do the trick...
select category_name, count(apps.app_category)
from categories
left join apps on apps.app_category = categories.category_id
group by category_name
order by count(apps.app_category)
See http://sqlfiddle.com/#!2/b0b75/5
Problem
I have tried for quite a while but I can't get any of the statements I try to work. Here are simplified versions of the tables and what I want to achieve: apps table ``` app_id app_category -------------------------- 1 2 2 4 3 2 4 1 ``` categories table ``` category_id category_name ------------------------------- 1 Arcade and Action 2 Brain and Puzzle 3 Casual 4 Casino ``` I want my statement to return the name of the most popular category, and also another one to return the most un-popular category if possible. For example, the most popular category is Brain and Puzzle as there are two apps with id = 2 in their category field. I have tried quite a variety of selects and would appreciate anyone's input. Thanks