title: Exclude rows with no associated row in a joined table
body: <p>I would like to get instances (rows) of table <code>foo</code> that do not have a reference in <code>bar</code></p>
  
  <p>Table <code>foo</code>:</p>
  
  <pre><code>+----+-----+
  | id | baz |
  +----+-----+
  |  1 |  23 |
  |  2 |  56 |
  |  3 |  45 |
  |  4 |  78 |
  +----+-----+
  </code></pre>
  
  <p>table <code>bar</code>:</p>
  
  <pre><code>+-----+--------+-----+
  | id  | foo_id | zab |
  +-----+--------+-----+
  |  7  |      2 | s1  |
  |  8  |      4 | s2  |
  +-----+--------+-----+
  </code></pre>
  
  <p>The result of my query should be instances of <code>foo</code> as below:</p>
  
  <pre><code>+----+-----+
  | id | baz |
  +----+-----+
  |  1 |  23 |
  |  3 |  45 |
  +----+-----+
  </code></pre>
  
  <p>Using the SQLAlchemy ORM, I have tried <code>join</code> and <code>outerjoin</code>, but the solution is still escaping me. Something tells me that the solution is easy and right in front of my face...</p>
  
  <pre><code>q = db.session.query(Foo).join(Baz, Baz.foo_id == Foo.id)
  
  q = db.session.query(Foo).outerjoin(Baz, Baz.foo_id == Foo.id)
  </code></pre>