title: SQL CASE STATEMENT in COUNT CLAUSE
body: <p>I'm trying to get a product's name and its number of sales from two separate tables.  </p>
  
  <p>My tables look something like this:</p>
  
  <pre><code>BOOK
  Book_ID | Book_Title | Book_Author  
  
  SOLD  
  Transaction_ID | Book_ID | Customer_ID  
  </code></pre>
  
  <p>I can get most of the results I want from the following query</p>
  
  <pre><code>SELECT b.Book_Title, COUNT(s.Book_ID) FROM Book b, Sold s 
  WHERE b.Book_ID = s.Book_ID 
  GROUP BY b.Book_Title;
  </code></pre>
  
  <p>However, this only displays products with at least one sale.  I would like to display all products, simply showing a zero if no sales have occurred.  I've been messing around with something like this:</p>
  
  <pre><code>SELECT b.Book_Title, 
         COUNT(CASE WHEN s.Book_ID IS NULL THEN 0 ELSE s.Book_ID END) 
  FROM Book b, Sold s WHERE b.Book_ID = s.Book_ID GROUP BY Book_Title;
  </code></pre>
  
  <p>But the <code>WHERE</code> clause is limiting the results to the ones with 1 or more sales.</p>
  
  <p>Can anyone suggest a way around this? I am using Oracle 10g.</p>
  
  <p>Thanks</p>