Fix issue with column ordering

It's especially important for compound queries (i.e. UNIONs).