Rearrange sql clauses.