Re: Subquery to select max(date) value

From: Rich Shepard <rshepard(at)appl-ecosys(dot)com>
To: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Subquery to select max(date) value
Date: 2019-02-15 20:38:59
Message-ID: alpine.LNX.2.20.1902151230581.31662@salmo.appl-ecosys.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 13 Feb 2019, Andrew Gierth wrote:

> You want LATERAL.

Andrew, et al,:

I found a couple of web pages describing the lateral join yet have not
correctly applied them. The manual's page did not help me get the correct
syntax, either. Think I'm close, however:

select p.person_id, p.lname, p.fname, p.direct_phone, o.org_name, a.next_contact
from people as p, organizations as o
lateral
(select a.next_contact
from activities as a
where a.next_contact is not null and a.next_contact <= 'today' and
a.next_contact > '2018-12-31'
order by person_id,next_contact);

When run I get this syntax error:

$ psql -f get_next_contact_dates.sql -d bustrac
psql:get_next_contact_dates.sql:10: ERROR: syntax error at or near "lateral"
LINE 3: lateral

What am I still missing?

Regards,

Rich

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Hugh Ranalli 2019-02-15 20:41:37 Channel binding not supported using scram-sha-256 passwords
Previous Message Andre Piwoni 2019-02-15 20:03:39 Re: Promoted slave tries to archive previously archived WAL file