title: Mysql order by rating - but capture all
body: <p>I have this PHP/MYSQL code which returns records from a table ordered by their ratings, from highest rated to lowest rated:</p>
  
  <pre><code>&lt;table width="95%"&gt;
      &lt;tr&gt;
      &lt;?php
          if (isset($_GET['p'])) {
              $current_page = $_GET['p'];
          } else {
              $current_page = 1;
          }
          $cur_category = $_GET['category'];
          $jokes_per_page = 40;
          $offset = ($current_page - 1) * $jokes_per_page;
  
          $result = mysql_query("
          select jokedata.id as joke_id, jokedata.datesubmitted as datesubmitted,
          jokedata.joketitle as joke_title, sum(ratings.rating)/count(ratings.rating) as average
          from jokedata inner join ratings
          on ratings.content_type = 'joke' and ratings.relative_id = jokedata.id
          WHERE jokecategory = '$cur_category'
          group by jokedata.id
          order by average desc
          limit $offset, $jokes_per_page
          ");
  
          $cell = 1;
          while ($row = mysql_fetch_array($result)) {
              if ($cell == 5) {
                  echo "&lt;/tr&gt;&lt;tr class=\"rowpadding\"&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;&lt;tr&gt;";
                  $cell = 1;
              }
              $joke_id = $row['joke_id'];
              $joke_title = $row['joke_title'];
              $joke_average = round($row['average'], 2);
  
              echo "&lt;td&gt;&lt;strong&gt;&lt;a class=\"joke_a\" href=\"viewjoke.php?id=$joke_id\"&gt;$joke_title&lt;/a&gt;&lt;/strong&gt; -average rating $joke_average.&lt;/td&gt;";
              $cell++;
          }
      ?&gt;
      &lt;/tr&gt;
      &lt;tr class="rowpadding"&gt;&lt;td&gt;&lt;/td&gt;&lt;/tr&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>It works perfectly but there is one problem - if an item does not have at least one rating, it will not be selected by the query at all!</p>
  
  <p>How can I remedy this? Thanks.</p>