Re: SELECT DISTINCT ON removes results

From: Geoff Winkless <pgsqladmin(at)geoff(dot)dj>
To: Guyren Howe <guyren(at)gmail(dot)com>, Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: SELECT DISTINCT ON removes results
Date: 2016-10-29 08:52:32
Message-ID: CAEzk6fdpXWWpZxZJbhLoEC3qE-zCaFg8uXU6gxiwNZpavu30Bg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 28 October 2016 at 21:39, Guyren Howe <guyren(at)gmail(dot)com> wrote:

> Using 9.5, this query:
>
> SELECT o.id,
> a.number AS awb
> FROM pt.orders o
> LEFT JOIN (
> SELECT DISTINCT ON ((string_agg(air_way_bills.number::text, ','::text)))
> string_agg(air_way_bills.number::text, ','::text) AS number,
> air_way_bills.order_id
> FROM pt.air_way_bills
> GROUP BY air_way_bills.order_id) a ON a.order_id = o.id
>
> ​From https://www.postgresql.org/docs/9.5/static/sql-select.
html#SQL-DISTINCT​


The DISTINCT ON expression(s) must match the leftmost ORDER BY expression(s).
The ORDER BY clause will normally contain additional expression(s) that
determine the desired precedence of rows within each DISTINCT ON group.

​Does the problem go away if you do that?​

​Geoff​

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Samuel Williams 2016-10-29 10:31:59 Re: initdb createuser commands
Previous Message Samuel Williams 2016-10-29 03:36:20 Re: initdb createuser commands