Re: Selecting table row with latest date

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Selecting table row with latest date
Date: 2021-08-19 17:38:24
Message-ID: CAKFQuwaN0UZCfW_vuR+UYztL93wm1RKcr9E+gow8wxz1Dc544A@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thursday, August 19, 2021, Rich Shepard <rshepard(at)appl-ecosys(dot)com> wrote:

> On Thu, 19 Aug 2021, Adrian Klaver wrote:
>
> So take David Johnston's query:
>> Select distinct on (person_nbr) ….. order by person_nbr, contact_date
>> desc;
>>
>
> Adrian,
>
> contact_date --------------
> 2021-08-17

What’s your point?

> Select distinct on (person_nbr) * from contacts where next_contact <=
>> current_date order by person_nbr, contact_date desc;
>
>
> Select distinct on (p.person_nbr) * from c.contacts
> from people as p, contacts as c
> where cnext_contact <= current_date and
> p.person_nbr = c.person_nbr
> order by p.person_nbr, c.contact_date desc;
>
> $ psql -d bustrac -f test_query.sql
> psql:test_query.sql:5: ERROR: syntax error at or near "from"
> LINE 2: from people as p, contacts as c
> ^
>

Yeah, you wrote two from clauses…

David J.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2021-08-19 18:58:25 Re: Licensing
Previous Message Rob Sargent 2021-08-19 17:25:18 Re: Selecting table row with latest date