Order by count:
SELECT val,COUNT(*) as count FROM temptable GROUP BY val ORDER BY count DESC;
"temptable" table:
id | val | ||
---|---|---|---|
1 | val1 | ||
2 | val2 | ||
3 | val3 | ||
4 | val2 | ||
5 | val3 | ||
6 | val3 |
Result after sql select:
val | count | ||
---|---|---|---|
val3 | 3 | ||
val2 | 2 | ||
val1 | 1 |
Order by count:
SELECT val,COUNT(*) as count FROM temptable GROUP BY val ORDER BY count DESC;
"temptable" table:
id | val | ||
---|---|---|---|
1 | val1 | ||
2 | val2 | ||
3 | val3 | ||
4 | val2 | ||
5 | val3 | ||
6 | val3 |
Result after sql select:
val | count | ||
---|---|---|---|
val3 | 3 | ||
val2 | 2 | ||
val1 | 1 |