title: SQL Query to retrieve messages from all user's friends
body: <p>I have 3 databases setup for a Twitter-clone website.</p>
  
  <p>Table 'users':</p>
  
  <pre><code>email | firstname | lastname | hash_password
  </code></pre>
  
  <p>Link Table 'friends':</p>
  
  <pre><code>email | friend
  </code></pre>
  
  <p>This lists all users and their friends.  Friendships are 1-way (like Twitter's "Following"/"Followers").
  <code>friends</code> table is a link table to list all users' friends.  So both <code>friends.user</code> and <code>friends.friend</code> are foreign keys to <code>users.email</code>.</p>
  
  <p>Table 'messages':</p>
  
  <pre><code>timestamp | user | content
  </code></pre>
  
  <p>What is an SQL query to retrieve all messages from a user and his friends?</p>
  
  <hr />
  
  <p>I've tried:</p>
  
  <pre><code>SELECT
    'timestamp', 
    user, 
    content 
  FROM
    messages
    INNER JOIN friends ON messages.user = friends.friend
  ORDER BY 'timestamp' DESC;
  </code></pre>
  
  <p>This seems to join them correctly, but how can I only get the messages for a specific user's (email address) friends.  Right now this just returns all messages.</p>
  
  <p>Thanks.</p>