agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Edward W. Rouse <erouse@comsquared.com>
To: 'Nathan Mailg' <nathanmailg@gmail.com>
To: pgsql-sql@postgresql.org
Subject: Re: removing duplicates and using sort
Date: Mon, 16 Sep 2013 10:04:40 -0400
Message-ID: <080201ceb2e5$b10e4380$132aca80$@com> (raw)
In-Reply-To: <CAN8Rhd2n84Yxd4QP0SXuyuO+K4f3scQnAYAwq53GDFojOSkAjw@mail.gmail.com>
References: <CAN8Rhd2n84Yxd4QP0SXuyuO+K4f3scQnAYAwq53GDFojOSkAjw@mail.gmail.com>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-sql>

Change the order by to order by lastname, firstname, refid, appldate

 

From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org]
On Behalf Of Nathan Mailg
Sent: Saturday, September 14, 2013 10:36 PM
To: pgsql-sql@postgresql.org
Subject: [SQL] removing duplicates and using sort

 

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 BY refid,
appldate DESC;

 

I worked on this awhile and is as close as I could get. So this returns rows
as you'd expect, except I need to somehow modify this query so it returns
the rows ordered by lastname, then firstname.

 

I'm using distinct so I get rid of duplicates in the table where refid (an
integer) is used as the common id that ties like records together. In other
words, I'm using it to get only the most recent appldate (a date) for each
group of refid's that match the lastname, firstname where clause.

 

I just need the rows returned from the query above to be sorted by lastname,
then firstname.

 

Hope I explained this well enough. Please let me know if you need more info.

 

Thanks!

view thread (4+ messages)  latest in thread

Message-ID: <080201ceb2e5$b10e4380$132aca80$@com>
Permalink:  ../080201ceb2e5$b10e4380$132aca80$@com/
Also on:    postgresql.org/message-id/080201ceb2e5$b10e4380$132aca80$@com

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: erouse@comsquared.com, nathanmailg@gmail.com
  Subject: Re: removing duplicates and using sort
  In-Reply-To: <080201ceb2e5$b10e4380$132aca80$@com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox