From: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com> |
---|---|
To: | Rich Shepard <rshepard(at)appl-ecosys(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Re: Selecting table row with latest date |
Date: | 2021-08-19 19:00:17 |
Message-ID: | 9f209af1-531d-4497-583f-5e9f5ea3a2ef@aklaver.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 8/19/21 10:17 AM, Rich Shepard 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
> 2019-05-14
> 2019-05-15
> 2021-08-17
> 2018-04-05
> 2021-08-17
> 2018-04-05
> 2021-07-23
> 2019-04-01
> 2019-05-10
> 2019-03-15
> 2021-08-17
> 2019-04-16
> 2019-05-15
> 2021-08-17
> 2019-05-29
> 2021-08-17
> 2019-05-29
> 2021-07-23
> 2021-08-12
> ...
So is the above the result of the query above or the query I posted below?
Why is there no other information to provide context?
Is it doing what you want?
>
>> and add the next_contact filter:
>>
>> 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
> ^
>
> I still am missing quite a bit.
>
> Rich
>
>
>
--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com
From | Date | Subject | |
---|---|---|---|
Next Message | Rich Shepard | 2021-08-19 19:34:05 | Re: Selecting table row with latest date [RESOLVED] |
Previous Message | Bruce Momjian | 2021-08-19 18:58:25 | Re: Licensing |