On 2 Rugs, 20:41, "Michael Bayer" <mike...@zzzcomputing.com> wrote: > naktinis wrote: > > I tried calling .subquery() method on each union subquery like this: > > q1 = Thing.query().filter(...).order_by(Thing.a.desc()).limit > > (1).subquery() > > q2 = Thing.query().filter(...).order_by(Thing.a.asc()).limit > > (1).subquery() > > q = q1.union(q2).order_by(Thing.id) > > I know you're not doing that since the alias object returned by subquery() > does not have a union() method.
Sorry, you are right. I used union(q1, q2). Just copied the old source from previous post. > > you'll have to wrap each subquery in a SELECT like this: > > q1 = sess.query(C).order_by(C.data).limit(2).subquery().select() > q2 = sess.query(C).order_by(C.data.desc()).limit(2).subquery().select() > > print sess.query(C).select_from(union(q1, q2)).order_by(C.data) Thanks, it works. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---