Index: query.py
===================================================================
--- query.py	(revision 6200)
+++ query.py	(working copy)
@@ -544,6 +544,11 @@
                     order = "ASC"
                 if "." in col_name:
                     table_prefix, col_name = col_name.split('.', 1)
+                    # accept table name not only the internal alias as prefix
+                    if joins:  
+                        for join_alias, join_vals in joins.items():
+                            if qn(table_prefix) == join_vals[0]:
+                                table_prefix = join_alias
                     table_prefix = qn(table_prefix) + '.'
                 else:
                     # Use the database table as a column prefix if it wasn't given,
