Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Need SQL to find LATEST child record
Message
De
15/04/2003 09:53:46
 
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Base de données, Tables, Vues, Index et syntaxe SQL
Titre:
Need SQL to find LATEST child record
Divers
Thread ID:
00777700
Message ID:
00777700
Vues:
50
Table INMATES - 1 rec per inmate. Primary key is cid
cid cinmate_number
1 0012345
2 0023456

Table ACCT_EVENTS - 1 rec per status changing event. Primary key is cid, foreign key into INMATES is cinmates_id. Status changing events are:
When inmates acct is created, ACCT_EVENTS rec is created showing status = "OPEN"
When inmates acct is closed, ACCT_EVENTS rec is created showing status = "CLOSED"
When inmates act is re-opened, ACCT_EVENTS rec is created showing status = "OPEN", etc.
An account can be opened, closed and opened again, many times.

cid cinmates_id ttxndatetm txnstatus
X1 1 04/01/03 12:00:00 AM OPEN
X2 1 04/05/03 04:00:00 AM CLOSED
X3 1 04/05/03 06:00:00 AM OPEN
X4 1 04/07/03 12:00:00 AM CLOSED
X5 2 04/01/03 08:00:00 AM OPEN
X6 2 04/03/03 04:00:00 AM CLOSED
X7 2 04/03/03 05:00:00 AM OPEN

I need to select all recs from INMATES where the latest record from ACCT_EVENTS indicates the current status is "OPEN"

In this example, ONLY INMATES rec where inmate number is 0023456 would be selected. I do need to capture INMATES.cInmate_Number and other extraneous fields and from ACCT_EVENTS, the ttxndatetm. The status will be a view parameter. In other words the same SQL stmt will be used to capture OPEN acct's and CLOSED acct's.

How to accomplish this is beyond my comprehension at this point. SORRY for the formatting. When I write this posting, the columns of data are laid out nicely but it squashes it together when posted.
Thanks,
John
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform