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
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
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
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
Use order by category.
select * from [table] order by category