Hey, I had this issue where doing something like:
My hosting server uses: MySQL 4.1.13a (MacOS), and they wont be upgrading till Mac OS panther is out unfortunately :( I use a later version on my dev box, and things work fine with a query like: In my User table mapper object: def getMostActive(cls): q = Query(cls).join('parent').group_by(cls.c.user_id).order_by(func.count(cls.c.user_id)).limit(limit).offset(offset) q.list() The above query returns something like here, which fails: SELECT tg_user.last_name AS tg_user_last_name, tg_user.profile_visits AS tg_user_profile_visits \nFROM tg_user JOIN post_data ON tg_user.user_id = post_data.user_owner_id GROUP BY tg_user.user_id ORDER BY count(tg_user.user_id) cid LIMIT 5 OFFSET 0; Changing the query manually to something like this passes: SELECT count(tg_user.user_id) cid, tg_user.last_name AS tg_user_last_name, tg_user.profile_visits AS tg_user_profile_visits \nFROM tg_user JOIN post_data ON tg_user.user_id = post_data.user_owner_id GROUP BY tg_user.user_id ORDER BY cid LIMIT 5 OFFSET 0; So, apparently it doesn't like me passing the func.count() directly to order by, but rather I should do a select on that, and then have an alias on it and order by this alias. Does anynoe know how I can do this with SA queries?? 1) select a func.count() column 2) Name an alias to it 3) use this alias with a .order_by thanks. --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---