title: Select from one table, and count from another table in same query
body: <p>I have quite a bit of knowledge about SQL queries.</p>
  
  <p>I'm trying to make gallery, and I need to select categories from table "cat_photos", which contain rows (id,name,cover,photo) and count number of photos from table "photos" which contain rows (id,thumb,photo,category).  </p>
  
  <p>Here is code which i use:</p>
  
  <p>1) Selecting categories</p>
  
  <pre><code>$query = mysql_query("SELECT * FROM cat_photos ORDER BY ID DESC");
                 while($data = mysql_fetch_array($query)) {       
          echo "&lt;li&gt;&lt;a href='photos.php?cat=$data[id]'&gt;&lt;img src='galleries/categories/$row[image]' alt='$row[name]' /&gt;&lt;/a&gt;
                &lt;div class='photodesc'&gt;&lt;div class='catname'&gt;&lt;a href='photos.php?cat=$row[id]'&gt;$row[name]&lt;/a&gt;&lt;/div&gt;
                &lt;div class='catcount'&gt;Number of photos in category&lt;/div&gt;&lt;/div&gt;&lt;/li&gt;"; }
  </code></pre>
  
  <p>2) Counting number of photos in category</p>
  
  <pre><code>$query = mysql_query("SELECT category, COUNT(photo) FROM photos GROUP BY category") or die(mysql_error());
                 while($row = mysql_fetch_array($query)){
          echo "Number of photos is ". $row['COUNT(photo)'] ." in cateogry ". $row['category'] .".";
          echo "&lt;br /&gt;"; }
  </code></pre>
  
  <p>Separated all works, but I can't find a way to merge them into one query.
  I have googleing for "UNION", "JOIN", "LEFT JOIN" options in MySql query but I could't together the pieces.</p>
  
  <p>I wonder if this is in general possible? 
  How in order that query look like?</p>