title: MySQL SELECT 2 tables with an INNER JOIN
body: <p>I've been working on some MySQL Joins but this one has got me a little confused.
  I have 3 tables, <code>friends</code>, <code>posts</code> and <code>activity</code>.</p>
  
  <p>Tables <code>posts</code> and <code>activity</code> both have a field <code>userid</code> which represents the user that the record belongs to. <code>friends</code> contains the fields <code>userid</code> and <code>friendid</code> to represent two users being friends.</p>
  
  <p>If possible, I would like to design a query which will display the records in <code>posts</code> AND <code>activity</code> from a user which is friends with the logged in user.</p>
  
  <p>I have tried the following query:</p>
  
  <pre><code>SELECT p.*, a.*
      FROM posts AS p, activity AS a
      INNER JOIN friends f ON (p.userid = f.friendid)
      WHERE f.userid = '(Logged In User ID)'
  </code></pre>
  
  <p>However, when I run the above query, I get the following error:</p>
  
  <p><code>Unknown column 'p.userid' in 'on clause'</code></p>
  
  <p>Any help would be much appreciated :)</p>