Note that you could always do something like: WITH original_query AS ( SELECT DISTINCT ... ) SELECT * FROM original_query ORDER BY lastname, firstname;
OR SELECT * FROM ( SELECT DISTINCT .... ) sub_query ORDER BY lastname, firstname I am thinking you cannot alter the existing ORDER BY otherwise your use of "DISTINCT ON" begins to mal-function. I dislike DISTINCT ON generally but do not wish to ponder how you can avoid it, so I'd suggest just turning your query into a sub-query like I show above. David J. -- View this message in context: http://postgresql.1045698.n5.nabble.com/removing-duplicates-and-using-sort-tp5770931p5771096.html Sent from the PostgreSQL - sql mailing list archive at Nabble.com. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql