Suppose, I want to show a list of users ordering by the most number of messages they have sent.
I have 2 tables: Users and Messages
Users
Messages
I h
You can sort using an alias:
alias
SELECT user, COUNT(1) as cnt FROM Messages GROUP BY user ORDER BY cnt DESC;
or position:
position
SELECT user, COUNT(1) as cnt FROM Messages GROUP BY user ORDER BY 2 DESC;