Sorry I am not explaining the situation properly
In your example I do not see how this code would give the maximum heightdate within the Patient ID and WeightDate.
Also the code looks for a data that exists in both tables but this is not the case in my situation.
I have copied the example below
+++++++++++++++++++++++++++++
I am joining 3 table by a 5 field key
Tables
Patient Information
Patient Weight
Patient Height
The Patient Information is the Primary Table and has only one record per key combination.
The Weight Table has many records that match the Key in the Patient Table
The Height Record can have many records that match the Key in the Patient Table
I only want the Height Record within a given Patient Chart Number that has the most recent date or the Maximum Date within the Chart Number
I have been using the Database Expert to join the tables but I sure wish I could get at the SQL statement so I could simply get the records I want.
How else would I make the selection I need
Patient Table - Institution Site ChartNumber CreateDate Type
Weight Table - Institution Site ChartNumber CreateDate Type Weight WeightDate
Height Table - Institution Site ChartNumber CreateDate Type Height HeightDate
The table below shows I am getting 2 HeightDates for every WeightDate.
I only want the most recent HeightDate
rptWeight
| Chart |
LastName |
FirstName |
Room |
NursingUnit |
IsLastAssessment |
Gender |
Kilograms |
WeightDate |
Height |
HeightDate |
| 000000308 |
Beaulne |
SANDRA |
232 B |
2B |
-1 |
Female |
39.8 |
20030101 |
146.0 |
20060804 |
| 000000308 |
Beaulne |
SANDRA |
232 B |
2B |
-1 |
Female |
39.8 |
20030101 |
152.0 |
20030514 |
| 000000308 |
Beaulne |
SANDRA |
232 B |
2B |
-1 |
Female |
37.9 |
20030201 |
146.0 |
20060804 |
| 000000308 |
Beaulne |
SANDRA |
232 B |
2B |
-1 |
Female |
37.9 |
20030201 |
152.0 |
20030514 |
I need the Maximum WeightDate and Weight within the ChartNumber