1
question category 
A           X
B           Y
C           X
D           X
E           Y

I want to make the output from the most frequent category

question category
A             X
C             X
D             X
B             Y
E             Y
1

3 Answers 3

3

You could try with join on the count for category

select m.question, m.category  
from my_table  m
inner join  (
  select category, count(*) num
  from my_table  
   group by category 
) t on t.category = m.category
order by t.num desc, m.category, m.question
Sign up to request clarification or add additional context in comments.

Comments

2

If you are running MySQL 8.0, you can use window functions for this. This avoids the need for a join.

select *
from mytable
order by 
    count(*) over(partition by category) desc,
    question 

Comments

-4

Use order by category.

select * from [table] order by category

1 Comment

This will just order them, but will not put the one that happens the most at the top

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.