I have this database:
As you can see, both of jtb_Affected_Target's foreign keys are linked to tbl_Targets.Target_ID. This allows me to relate targets from the same table as Children or Parents to other targets.
Here is frm_Target (based on tbl_Targets):
The subforms allow me to link targets together as either Child or Parent targets. As you can see above, "*@gmail.com" has two child targets: email1@gmail.com and email2@gmail.com. Navigating to those records in frm_Target will show *@gmail.com as a Parent Target:
I also have a target, email3@gmail.com, that does not have a parent target:
It would make sense to make it a Child Target of *@gmail.com, just like email1@gmail.com and email2@gmail.com. But, before I can get to that point, I would need a query that:
#1 is easy -- I have a query ("qry_Targets_Orphans"):
Which yields the following results:
You'll notice in the above screenshot, there are also targets *@*email.com and test.123@subdomain.email.com... these should also be linked together as Parent-Child. How do I modify this query so that it can find targets where the names are LIKE each other? (email3@gmail.com is LIKE *@gmail.com; test.123@subdomain.email.com is LIKE *@*email.com) Ideally, there would be a third column that shows the matched, potential Parent Target. I attached a copy of the database for you to see.

As you can see, both of jtb_Affected_Target's foreign keys are linked to tbl_Targets.Target_ID. This allows me to relate targets from the same table as Children or Parents to other targets.
Here is frm_Target (based on tbl_Targets):

The subforms allow me to link targets together as either Child or Parent targets. As you can see above, "*@gmail.com" has two child targets: email1@gmail.com and email2@gmail.com. Navigating to those records in frm_Target will show *@gmail.com as a Parent Target:


I also have a target, email3@gmail.com, that does not have a parent target:

It would make sense to make it a Child Target of *@gmail.com, just like email1@gmail.com and email2@gmail.com. But, before I can get to that point, I would need a query that:
- IDENTIFIES targets that do not currently have any Parent targets, and
- MATCHES them to potential Parent target candidates.
#1 is easy -- I have a query ("qry_Targets_Orphans"):
Code:
SELECT
tbl_Targets.*
FROM
tbl_Targets
LEFT JOIN jtb_Affected_Targets
ON tbl_Targets.Target_ID = jtb_Affected_Targets.Child_Target_ID
WHERE
jtb_Affected_Targets.Child_Target_ID Is Null

You'll notice in the above screenshot, there are also targets *@*email.com and test.123@subdomain.email.com... these should also be linked together as Parent-Child. How do I modify this query so that it can find targets where the names are LIKE each other? (email3@gmail.com is LIKE *@gmail.com; test.123@subdomain.email.com is LIKE *@*email.com) Ideally, there would be a third column that shows the matched, potential Parent Target. I attached a copy of the database for you to see.