title: Sort by a column in a union query in SqlAlchemy SQLite
body: <p>As explained in <a href="https://stackoverflow.com/questions/19232596/how-to-sort-by-a-column-in-union-query-in-sqlalchemy">this question</a>, you can use string literals to do <code>order by</code> in <code>union</code>s.</p>
  
  <p>For example, this works with Oracle:</p>
  
  <pre><code>querypart1 = select([t1.c.col1.label("a")]).order_by(t1.c.col1).limit(limit)
  querypart2 = select([t2.c.col2.label("a")]).order_by(t2.c.col2).limit(limit)
  query = querypart1.union_all(querypart2).order_by("a").limit(limit)
  </code></pre>
  
  <p>The order-by can take a string literal, which is the name of the column in the union result.</p>
  
  <p>(There are gazillions of rows in partitioned tables and I'm trying to paginate the damn things)</p>
  
  <p>When running against SQLite3, however, this generates an exception:</p>
  
  <pre><code>sqlalchemy.exc.OperationalError: (OperationalError) near "ORDER": syntax error
  </code></pre>
  
  <p>How can you <code>order by</code> the results of a <code>union</code>?</p>