If you retrieve your results into an arrayref (e.g. with selectall_arrayref), the rows in the array will be in the order returned by the SQL query, in this case ordered by lastname. If you use TMPL_LOOP to display the arrayref, it will display the results in the order they occur in the arrayref. What's the problem?