From: | Rich Shepard <rshepard(at)appl-ecosys(dot)com> |
---|---|
To: | pgsql-general(at)lists(dot)postgresql(dot)org |
Subject: | Refining query statement |
Date: | 2019-01-15 15:39:08 |
Message-ID: | alpine.LNX.2.20.1901150738320.5845@salmo.appl-ecosys.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Working with my sales/client management system using psql I have a select
statement to identify contacts to be made. This statement works:
select (C.contact_id, C.lname, C.fname, C.direct_phone, O.org_name,
A.next_contact)
from Contacts as C, Organizations as O, Activities as A
where C.org_id = O.org_id and C.contact_id = A.contact_id and
A.next_contact <= 'today' and A.next_contact > '2018-12-31' and
A.next_contact is not null;
but would benefit from tweaking. When I have had multiple contacts with
someone I want only the most recent one displayed, not all, and they should
be no more ancient than a defined period (e.g., a month).
I want to learn how to make this query cleaner and more flexible. When I
write the UI for this I want to be able to specify a data range in addition
to a fixed 'today'. Pointers on what to read will be very helpful.
TIA,
Rich
From | Date | Subject | |
---|---|---|---|
Next Message | Thomas Kellerer | 2019-01-15 15:47:32 | Re: Refining query statement |
Previous Message | Sherrylyn Branchaw | 2019-01-15 12:57:13 | Re: pg_restore restores privileges differently from psql |