Hence my suggestion, above, that the simplest approach is simply to remove any assumptions (hence, dependencies) upon the order of the field-names in the query. Since you have full control over the entire procedure, simply deal with the two problems separately. The SELECT statement only need make sure that the necessary columns are returned. Build a separate (Perl) list containing the column-names in the order that you need to present them. Then, iterate through that list. Problem (neatly) solved.