I want to count sites on some languages for statistics and use this query:
SELECT `language_id` , count( * ) AS 'num'
FROM sites
WHERE `language_id` != 0
GROUP BY `language_id`
ORDER BY 'num' ASC
But result isn’t ordered by num field. What is wrong in my SQL?
The problem is that you are quoting your alias
numusing the single quote'character, which happens to be valid in creating the alias but is treated as a literal string in theORDER BYclause: since it is invariant across the results it does not affect the sort order. The backtick character is valid in both clauses. Try instead: