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
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