title: Mysql query to select all the items in category table and total items in product table belonging to each category ordering by total count
body: <p>I have two tables category and products. Category table has id, name and product table has id, cat_id, name, details, etc. I need a mysql query that will select each category and total count of products belonging to each category and order the result by total count. Can anyone help me?</p>
  
  <p>Category table</p>
  
  <pre><code>+----+------+
  | id | name |
  +----+------+
  |  1 | cat1 |
  |  2 | cat2 |
  |  3 | cat3 |
  +----+------+
  </code></pre>
  
  <p>Product table</p>
  
  <pre><code>+----+-------+--------+   
  | id | name  | cat_id |    
  +----+-------+--------+
  |  1 | prod1 |      1 |    
  |  2 | prod2 |      1 |    
  |  3 | prod3 |      3 |    
  |  4 | prod4 |      2 |    
  |  5 | prod5 |      2 |
  |  6 | prod6 |      2 |    
  +----+-------+--------+
  </code></pre>
  
  <p>Expected output table</p>
  
  <pre><code>+----+------+-------+    
  | id | name | count |    
  +----+------+-------+    
  |  2 | cat2 |     3 |    
  |  1 | cat1 |     2 |    
  |  3 | cat3 |     1 |  
  +----+------+-------+
  </code></pre>