title: SQL Ordering Results from Other Query
body: <p>I have two tables:</p>
  
  <pre><code>`users`
  `id` INT(11)
  `name` VARCHAR(30)
  
  `items`
  `id` INT(11)
  `name` VARCHAR(30)
  `owner` VARCHAR(30)
  </code></pre>
  
  <p>And here is my problem: I'm trying to order the <code>users</code> table by the number of unique items that they have in the <code>items</code> table.</p>
  
  <p>To get unique number of items:</p>
  
  <pre><code>SELECT * FROM `items` WHERE `owner`='".$ownername."' GROUP BY `name`
  </code></pre>
  
  <p>Running this query gives me the number of unique items for some <code>$ownername</code>.</p>
  
  <p>What I'm trying to do is order the <code>users</code> table by the number of unique items that they have in the <code>items</code> table, and I'm not sure how I would do that.</p>