I thought I had this the other day when AL helped me but not quite there.
2 tables:
Inmates - 1 rec per inmate
Acct_Events - 1 rec per inmate per status change. Status change events are "OPEN" when the inmate is created, "CLOSED" when the inmate is released, "OPEN" when the inmate is un-released, etc.
I am using surrogate keys: Inmates.cid is primary key; acct_events.cinmates_id is foreign key into inmates.cid
Basically I need to write SQL to select all inmates recs where LATEST acct_events record is "OPEN"
Here is what I have but, of course, it is including all acct_events recs where status is "OPEN" rather than ONLY inmates recs where LATEST acct_events is "OPEN".
SELECT Inmates.cid, Inmates.cinmate_number,;
MAX(acct_events.tdatetm) as dstatusdate;
FROM inmatetrustfund!inmates, inmatetrustfund!acct_events;
WHERE acct_events.cinmates_id = inmates.cid AND acct_events.cstatus = "OPEN";
GROUP BY Inmates.cid;
ORDER BY cname;
INTO CURSOR mycursor
Thanks. I've tried everything over the last few hours. I do need HELP!
John
2 tables:
Inmates - 1 rec per inmate
Acct_Events - 1 rec per inmate per status change. Status change events are "OPEN" when the inmate is created, "CLOSED" when the inmate is released, "OPEN" when the inmate is un-released, etc.
I am using surrogate keys: Inmates.cid is primary key; acct_events.cinmates_id is foreign key into inmates.cid
Basically I need to write SQL to select all inmates recs where LATEST acct_events record is "OPEN"
Here is what I have but, of course, it is including all acct_events recs where status is "OPEN" rather than ONLY inmates recs where LATEST acct_events is "OPEN".
SELECT Inmates.cid, Inmates.cinmate_number,;
MAX(acct_events.tdatetm) as dstatusdate;
FROM inmatetrustfund!inmates, inmatetrustfund!acct_events;
WHERE acct_events.cinmates_id = inmates.cid AND acct_events.cstatus = "OPEN";
GROUP BY Inmates.cid;
ORDER BY cname;
INTO CURSOR mycursor
Thanks. I've tried everything over the last few hours. I do need HELP!
John