 <p>Solution:</p> <pre><code>SELECT tag, COUNT(*)AS tags_count FROM ( SELECT post_n, tag FROM tags ORDER BY post_n DESC LIMIT 20 ) AS temp GROUP BY tag HAVING tags_count&gt;=2 ORDER BY post_n DESC LIMIT 5 </code></pre> <p>Of course need to change limit in the first selection, otherwise there will be plenty to choose from.</p> <p>P. S. Sorry that is poorly formulated question, my english very bad.</p>