title: Self join query to SQlAlchemy ORM using alias
body: <p>I'm trying to convert the following SQL query to a SQlAlchemy statement and facing the error:</p>
  <blockquote>
  <p>sqlalchemy.exc.InvalidRequestError: Don't know how to join to
  &lt;AliasedInsp at 0x7fa9c5832be0; Task(Task)&gt;. Please use the
  .select_from() method to establish an explicit left side, as well as
  providing an explicit ON clause if not present already to help resolve
  the ambiguity.</p>
  </blockquote>
  <p>SQL Query:</p>
  <pre><code>select t2.* 
  from task as t1 
  inner join task as t2 on t1.g_id  = t2.g_id  
  where t1.id = 'task_id';
  </code></pre>
  <p>SQlAlchemy statement:</p>
  <pre><code>table_a = aliased(Task)
  table_b = aliased(Task)
  query = (
      self.db.query(Task)
      .join(table_a, table_b).filter(table_b.group_id == table_a.group_id)
      .filter(table_a.id == task_id)
     )
  </code></pre>
  <p>Tried following the SQLAlchemy documentation on alias but could not figure out the error.</p>