Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread Adrian Klaver
On 8/19/21 3:07 PM, Rich Shepard wrote: On Thu, 19 Aug 2021, David G. Johnston wrote: David, I'm not at all surprised as I use postgres infrenquently. Once I have queries producing results I need for my business tracking or client data I just use them. I'm neither a professional DBA nor data

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, David G. Johnston wrote: Well, in this case I suspect you had made a different mistake which caused the error message (probably the max(c.next_contact)) but instead of solving the original problem (removing the max(...)) you decided that two wrongs (adding or extending a gro

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread David G. Johnston
On Thu, Aug 19, 2021 at 2:52 PM Rich Shepard wrote: > On Thu, 19 Aug 2021, David G. Johnston wrote: > > > I thought you said (p.person_nbr, c.contact_date) is already unique? > > Yes, that's the PK for the contacts table. I'm still unsure what needs to > be > explicitly included in a query. Quite

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, David G. Johnston wrote: I thought you said (p.person_nbr, c.contact_date) is already unique? David, Yes, that's the PK for the contacts table. I'm still unsure what needs to be explicitly included in a query. Quite often I leave out a column and postgres tells me it need

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread David G. Johnston
On Thu, Aug 19, 2021 at 12:34 PM Rich Shepard wrote: > group by p.person_nbr, c.contact_date > I thought you said (p.person_nbr, c.contact_date) is already unique? David J.

Re: Selecting table row with latest date [RESOLVED]

2021-08-19 Thread Rich Shepard
On Thu, 19 Aug 2021, David G. Johnston wrote: Yeah, you wrote two from clauses… David, Mea culpa! I did. Got that fixed. Now, this query: --- Select distinct on (p.person_nbr) p.person_nbr, c.contact_date, max(c.next_contact) as next_contac from contacts, people as p, contacts as c where