import itertools as it
fields = {'a': ('col1', 'col2'), 'b': ('col1', 'col3')}
fields_sql = ', '.join("{t}.{f} as '{t}.{f}'".format(f=f, t=t) for t in
    fields for f in fields[t])
sql = """SELECT {f}
    FROM a
        JOIN b ON ...
    WHERE ..."""
force mysqldb dict cursor to return prefix all column names with table name