I have a table that contains records of drawings called 'tblDWGIndexMain'. Each record has drawing number field 'DWG' and project number field 'ProjectNumber' neither of these fields is unique, as a ProjectNumber can affect multiple drawings.
The best way I could think to explain this is in a parent-child relationship between the parent drawing and the child project drawings, where the record with a DWG number but no ProjectNumber is the parent and the record/s with the ProjectNumber/s are the children. As you can see below, there are some 'orphan' records where they have both DWG and ProjectNumber but there is no corresponding 'parent' record (without ProjectNumber).
e.g. the table can (and does) have records in this fashion:
tblDWGIndexMain
DWG | ProjectNumber
10000
10001
10001 P11001
10002
10002 P11001
10003 P11002
The record for 10003-P11002 is an orphan, with no parent record existing that contains 10003 without a ProjectNumber.
I'm not concerned about any records that have a DWG number but no ProjectNumber, but I do want to identify all records that have both a DWG number and a ProjectNumber but that do not have a corresponding parent record with only a DWG number (and no ProjectNumber).
So far I have the following:
But it is not giving the results I need, it is still including records that do have parent records.
I can check the number of parent records against the number of child records by using these two queries:
qry_ProjectDrawings:
(returns 5983 records)
and then:
(returns 3412 records)
That gives all parent records that have corresponding child records, but I need to go the other way. (Also, it's not a direct correlation between the number of child records and the number of parent records because one parent can have many children.)
e.g. this is a possibility:
tblDWGIndexMain
DWG | ProjectNumber
10000
10001
10001 P11001
10002
10002 P11001
10002 P11002
10002 P11003
10003 P11002
Is the first querry above heading in the right direction? Or am I barking up the wrong tree entirely?
Thanks for looking.
Cheers,...Jon.
The best way I could think to explain this is in a parent-child relationship between the parent drawing and the child project drawings, where the record with a DWG number but no ProjectNumber is the parent and the record/s with the ProjectNumber/s are the children. As you can see below, there are some 'orphan' records where they have both DWG and ProjectNumber but there is no corresponding 'parent' record (without ProjectNumber).
e.g. the table can (and does) have records in this fashion:
tblDWGIndexMain
DWG | ProjectNumber
10000
10001
10001 P11001
10002
10002 P11001
10003 P11002
The record for 10003-P11002 is an orphan, with no parent record existing that contains 10003 without a ProjectNumber.
I'm not concerned about any records that have a DWG number but no ProjectNumber, but I do want to identify all records that have both a DWG number and a ProjectNumber but that do not have a corresponding parent record with only a DWG number (and no ProjectNumber).
So far I have the following:
Code:
SELECT DISTINCTROW A.*
FROM tblDWGIndexMain As A LEFT JOIN tblDWGIndexMain As B ON A.DWG = B.DWG
WHERE (((A.ProjectNumber) Is Not Null)) ORDER BY A.DWG, A.ProjectNumber;
But it is not giving the results I need, it is still including records that do have parent records.
I can check the number of parent records against the number of child records by using these two queries:
qry_ProjectDrawings:
Code:
SELECT *
FROM tblDWGIndexMain
WHERE ProjectNumber is not null;
(returns 5983 records)
and then:
Code:
SELECT *
FROM tblDWGIndexMain INNER JOIN qry_ProjectDrawings ON (tblDWGIndexMain.DWG = qry_ProjectDrawings.DWG
AND tblDWGIndexMain.ProjectNumber is null) ORDER BY tblDWGIndexMain.DWG;
(returns 3412 records)
That gives all parent records that have corresponding child records, but I need to go the other way. (Also, it's not a direct correlation between the number of child records and the number of parent records because one parent can have many children.)
e.g. this is a possibility:
tblDWGIndexMain
DWG | ProjectNumber
10000
10001
10001 P11001
10002
10002 P11001
10002 P11002
10002 P11003
10003 P11002
Is the first querry above heading in the right direction? Or am I barking up the wrong tree entirely?
Thanks for looking.
Cheers,...Jon.
Last edited: