title: Find all records that have X tags ordered by ascending time, BUT, the ones that match the most tags should be grouped first
body: <p>Ok, this is a little hard to explain, and the title is not the best :/ but, basically, I have 3 tables and I'm trying to write a query that returns them with 2 levels of ordering. The first by the amount of "tags" each row has, and the second by when that row was created.</p>
  
  <pre><code>Table1: Items
    * ID
    * Name
    * CreatedAt
  
  Table2: Tags
    * ID
    * Name
  
  Table3: TaggedItems
    * TagID
    * ItemID
  </code></pre>
  
  <p>And I would like to list all items that have 1 or more tags, in ascending order by when they when created. But, and here's where I'm having issues, I want the ordering to be based on the number of tags that match an item, and, within that ordering, apply the ascending criteria.</p>
  
  <p>So, let's say I have:</p>
  
  <pre><code>Item1 -&gt; CreatedAt(0), Tags(A, B)
  Item2 -&gt; CreatedAt(0), Tags(A)
  Item3 -&gt; CreatedAt(1), Tags(B)
  Item4 -&gt; CreatedAt(1), Tags(A, B)
  
  </code></pre>
  
  <p>Then searching for all items with tags A and B must return first <code>Item1</code> and <code>Item4</code> and order those by ascending <code>CreatedAt</code>. And then <code>Item2</code> and <code>Item3</code> and order those by <code>CreatedAt</code> ascending. So the result would be:</p>
  
  <pre><code>* Item1
  * Item4
  * Item2
  * Item3
  </code></pre>
  
  <p>I am inexperienced with SQL so maybe there are very well known solutions to this if I'm even explaining it correctly? </p>
  
  <p>Appreciate any help!</p>