Re: problem with distinct rows

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: tony <tony(at)tgds(dot)net>
Cc: postgres list <pgsql-general(at)postgresql(dot)org>
Subject: Re: problem with distinct rows
Date: 2005-03-08 11:29:01
Message-ID: 20050308112853.GE13845@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Mar 08, 2005 at 12:22:35PM +0100, tony wrote:
> Le mardi 08 mars 2005 à 11:04 +0100, Martijn van Oosterhout a écrit :
> > You can put the DISTINCT ON() query as a subquery, and an ORDER BY in
> > the outer query.
>
> That was my first guess
>
> select number.inventorynumber, name, first_name
> from (select distinct on (inventorynumber) inventorynumber from works)
> as number, artist, blah
> order by name

and, does it work? Obviously you need to put the joins in and such. But
the outer query should be last, like:

SELECT * FROM
(... subquery ...) AS x
ORDER BY name;

The outer query is only for ordering, the joins, etc should all be in
the subquery...

--
Martijn van Oosterhout <kleptog(at)svana(dot)org> http://svana.org/kleptog/
> Patent. n. Genius is 5% inspiration and 95% perspiration. A patent is a
> tool for doing 5% of the work and then sitting around waiting for someone
> else to do the other 95% so you can sue them.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Hugo 2005-03-08 11:51:53 Re: Restoring db objects , help needed
Previous Message tony 2005-03-08 11:22:35 Re: problem with distinct rows