I'm struggling with a query returning too many records.
I have 3 related tables.
tblPatients
tblOperations
tblTargets
Each patient in tblPatients can have more than one operation (one-many)
Each Operation in tblOperations can have many targets (many-many)
The unique key across tables is PtFileNumber
So one patients data would look something like this (only bare bones given)
Expand|Select|Wrap|Line Numbers
- (tblPatient)
- KENROT56 (ie had 3 operations )
- (tblOperations)
- 12/01/06 (3 records, one operation on each on these dates )
- 10/02/06
- 15/05/06
- (tblTarget)
- 12/01/06 (4 records, ie for one operation there are 2 targets)
- 12/01/06
- 10/02/06
- 10/02/06
Not all the data is entered at once but it is always entered in order ie Patient ID followed by Operation followed by Target.
I have one query that finds all Patients that do not (yet) have a corresponding Operation - works fine.
Then I have another query that is supposed to return all patients from the operations table that do not already have a matching date in the target table. Here I get the records I want plus records I don't want for SOME patients. So from my lists above I want to see returned ONLY kenrot56 15/05/06 instead I might get kenrot56 15/05/06 AND 10/02/06 .why?
Expand|Select|Wrap|Line Numbers
- <<SELECT DISTINCTROW tblOperation.date, tblOperation.PtFileNumber
- FROM tblOperation LEFT JOIN tblTargetSites ON tblOperation.PtFileNumber = tblTargetSites.ptFileNumber
- WHERE (((tblOperation.date) In (SELECT [date] FROM [tblOperation] where [date] <> [operationdate])))
- ORDER BY tblOperation.date;>>
sorry to be long winded Does this make sense?
Cheers
Gem