SQL Sort by group size
<p>I want to make a select query which groups rows based on a given column and then sorts by size of such groups.</p>

<p>Let's say we have this sample data:</p>

<pre><code>id type
1   c
2   b
3   b
4   a
5   c
6   b
</code></pre>

<p><strong>I want to obtain the following</strong> by grouping and sorting the column 'type' in a descending way:</p>

<pre><code>id type
2   b
3   b
6   b
1   c
5   c
4   a
</code></pre>

<p>As of now I am only able to get the count of each group but that is not exactly what I need:</p>

<pre><code>SELECT *, COUNT(type) AS typecount
FROM sampletable
GROUP BY type
ORDER BY typecount DESC, type ASC

id type count
2   b    3
1   c    2
4   a    1
</code></pre>

<p>Can anybody please give me a hand with this query?</p>

<p>Edit:
Made 'b' the biggest group to avoid coming to the same solution by using only SORT BY </p>