title: Trying to take an average of a column with three inner join tables MySQL
body: <p>I'm trying to get the average rating for the <code>rate</code> column in my <code>rating</code> table. After looking up many ways to do this, nothing seems to work for me. It does however work if I don't try to take the average.</p>
  
  <p>Here's my code (Attempt 1):</p>
  
  <pre><code>    $sql = "SELECT * FROM users 
             INNER JOIN mentor ON users.id = mentor.id 
             INNER JOIN (SELECT AVG(rating.rate) AS average 
             FROM rating GROUP BY rating.owner) 
             ON mentor.id = rating.owner ORDER BY RAND()";
  </code></pre>
  
  <p>Here's my code (Attempt 2):</p>
  
  <pre><code>   $sql = "SELECT users.id, users.username, 
             mentor.industry, mentor.city,  
             AVG(rating.rate) AS average FROM users 
             INNER JOIN mentor ON users.id = mentor.id 
             INNER JOIN rating ON mentor.id = rating.owner
             ORDER BY RAND()";
  </code></pre>
  
  <p>The code after the <code>SELECT</code> statement is this:</p>
  
  <pre><code>$res = mysqli_query($db,$sql) or die(mysqli_error());               
  if (mysqli_num_rows($res)&gt;0) {
      while ($row=mysqli_fetch_assoc($res)){
          $variable= $row['column'];
  // more variable naming
     }
  }
  </code></pre>
  
  <p>Whenever I re-load my page, it is completely white. The console log says, "Failed to load resource: the server responded with a status of 404 (Not Found)". Not really sure what to do next. Thanks for any advice, suggestions!</p>
  
  <p>The <code>owner</code>column is = mentor.id = users.id</p>