sql: clean by sql generation and column reordering on selects

http://stackoverflow.com/questions/25914329/rearrange-columns-in-sqlalchemy-select-object/25932733#25932733