title: SQLAlchemy: exclude rows taken from a subquery on a query
body: <p>Abstraction of my problem, I have 2 <a href="http://i.imgur.com/GRs6Gxc.jpg?1" rel="noreferrer">tables</a>. A User table, and a Friendship table.</p>
  
  <p>I'm trying to make a query to list all the users available to be added as friend to User 1, Alice, and also excluding herself, using SQLAlchemy.</p>
  
  <p>Considering there could be a lot of friendships, to find Alice's friends:  </p>
  
  <pre><code>friend_subquery = db.session.query(Friendship).filter_by(User_id=1).subquery()
  </code></pre>
  
  <p>Now I want all the users listed, except Alice, and her friends, Bob and Jack.  </p>
  
  <pre><code>friends = (db.session.query(User).
              filter(User.ID != 1).
              outerjoin(friend_subquery,
                        User.ID != friend_subquery.c.Friend_id))
  </code></pre>
  
  <p>My expected result would have been to get User 4 and 5, but this query
  returns all except Alice herself. The condition of </p>
  
  <pre><code>User.ID != friend_subquery.c.Friend_id
  </code></pre>
  
  <p>seem NOT to be working as expected.</p>
  
  <p>P.S. I've done my homework of searching, reading docs, but couldn't figure it out. Thanks for your time.</p>