Re: [SQL] removing duplicates and using sort

2013-09-17 Thread Nathan Mailg
Yes, that's correct, modifying the original ORDER BY gives: ORDER BY lastname, firstname, refid, appldate DESC; ERROR: SELECT DISTINCT ON expressions must match initial ORDER BY expressions Using WITH works great: WITH distinct_query AS ( SELECT DISTINCT ON (refid) id, refid, lastname, firs

[SQL] removing duplicates and using sort

2013-09-14 Thread Nathan Mailg
I'm using 8.4.17 and I have the following query working, but it's not quite what I need: SELECT DISTINCT ON (refid) id, refid, lastname, firstname, appldate FROM appl WHERE lastname ILIKE 'Williamson%' AND firstname ILIKE 'd%' GROUP BY refid, id, lastname, firstname, appldate ORDER