title: SQLAlchemy : Column name on union_all
body: <p>Here is the mssql code snippet</p>
  
  <pre><code>(Select column_name_1 from table_name_1  with(nolock)  Where column_name_2='Y'
  UNION ALL
  Select column_name_1 from table_name_2  with(nolock)  Where column_name_2='Y'
  )ae ON ae.column_name_1 = '1234'
  </code></pre>
  
  <p>I want to implement this in sqlalchemy and here is how i would approach it</p>
  
  <pre><code>q1 = session.query(table_name_1.column_name_1).filter(table_name_1.column_name_2=='Y')
  q2 = session.query(table_name_2.column_name_1).filter(table_name_2.column_name_2=='Y')
  
  q3 = q1.union_all(q2)
  </code></pre>
  
  <p>but</p>
  
  <p>How would i get the column_name_1 from q3. How would i do this?</p>
  
  <pre><code>q3.column_name_1 == '1234'
  </code></pre>
  
  <p>went through the <a href="http://docs.sqlalchemy.org/en/rel_0_9/" rel="nofollow noreferrer">sqlalchemy doc</a></p>
  
  <p>Found similar questions asked <a href="https://stackoverflow.com/questions/21777730/sort-by-a-column-in-a-union-query-in-sqlalchemy-sqlite">here</a></p>