title: Reducing duplicate JOIN clauses produced by SQLAlchemy
body: <p>I'm currently having trouble finding a way to reduce superfluous <code>JOIN</code> clauses produced by SQLAlchemy eager loading. I am currently querying <code>TableA</code>, which eagerly loads <code>TableB</code>, and <code>TableB</code> eagerly loads <code>TableC</code>. </p>
  
  <p>My queries also invole <em>explicit</em> joins to both <code>TableB</code> and <code>TableC</code> in order to filter on columns of those tables. However, it produces verbose SQL such as the following:</p>
  
  <pre><code>  SELECT * FROM TableA 
             JOIN TableB             ON TableA.fk == TableB.id
             JOIN TableC             ON TableB.fk == TableC.id
  LEFT OUTER JOIN TableB AS TableB_1 ON TableA.fk == TableB.id
  LEFT OUTER JOIN TableC AS TableC_1 ON TableB.fk == TableC.id
  </code></pre>
  
  <p>I'm currently using <code>lazy='joined'</code> on the backreferences to eagerly load <code>TableB</code> and <code>TableC</code> from <code>TableA</code> queries. Loading this data with a subquery creates an N+1 select issue (so switching from eager to lazy loading is not an option).</p>
  
  <p>I've tried also adding <code>innerjoin=True</code> to the backreference, which replaced the <code>LEFT OUTER JOIN</code> clauses with inner joins (just <code>JOIN</code> in the output). I was hoping that SQLAlchemy would merge identical join clauses, but it doesn't seem to.</p>
  
  <p>Is there a way to specify either on the query or on the relationship that identical join clauses should not be duplicated?</p>