Hi there,
just wondering if it is possible to get the top 10 COUNT results and ordering by COUNT and alphabetically?
I have the following tables,
tags
-------
id | title
.
tagged
------
tag_id | post_id
And the following SQL query
SELECT tag.*, COUNT(td.tag_ID) AS tagcount
FROM Tagged td
LEFT JOIN Tags tag ON td.tag_ID = tag.tag_ID
GROUP BY td.tag_ID
ORDER BY tagcount DESC, tag.tag_Title ASC
Any ideas?
Thanks in advance
Edit
Sorry if I didnt explain it properly.
The query works and I didnt add LIMIT 10 due to wanting to see the entire result set first.
The query I have works, however at the following example result
tag_ID tag_Title tagcount
1 Science 3
3 Chemistry 2
4 Misc 1
5 Maths 1
2 Sport 1
I would want Chemistry to come above Science though.
i.e. top ten highest counts.. sorted alphabetically
Result
Thanks to you both.. Daniel and Sled.
Here is a working example
(
SELECT t.*, COUNT(*) AS tagcount
FROM tagged td
LEFT JOIN tags t ON (t.id = td.tag_id)
GROUP BY td.tag_id
ORDER BY tagcount DESC, t.title ASC
LIMIT 3
) ORDER BY title ASC;