Re: removing duplicates and using sort - Mailing list pgsql-sql

From Nathan Mailg
Subject Re: removing duplicates and using sort
Date
Msg-id 309ABE98-2643-4E6B-B5C9-FF68271B9661@gmail.com
Whole thread Raw
In response to Re: removing duplicates and using sort  (David Johnston <polobo@yahoo.com>)
List pgsql-sql
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, firstname, appldate       FROM appl WHERE
lastnameILIKE 'Williamson%' AND firstname ILIKE 'd%'       GROUP BY refid, id, lastname, firstname, appldate
ORDERBY refid, appldate DESC   ) 
SELECT * FROM distinct_query ORDER BY lastname, firstname;

Thank you!




pgsql-sql by date:

Previous
From: David Johnston
Date:
Subject: Re: removing duplicates and using sort
Next
From: Enrico Oliva
Date:
Subject: xmlElement and \n