Are you asking for
(1) A list of children that are not related to a given parent (which I originally assumed).
(2) A list of parents who have no children
or
(3) A list of children who have no parents
You're right - the above query would give you all of the children that don't belong to a given parent - potentially a huge list!
Ah - then my original suggestion will give you exactly that. However, I might have confused you - instead of
SELECT <desired columns>
FROM my_table
WHERE child_column <> parent_column;
I should have said
SELECT <desired columns>
FROM my_table
WHERE child_column <> parent_column_value;
You would supply the parent's value when you run the query.
However, you confuse me with your response:
"Your suggestion would likely get me all of the children related to other parents, not those related to the children themselves."
I didn't see where there was a requirement to relate children to children.
But if what you are looking for is "a list of children (which may or may not be related to other parents) but are not related to a given specific parent", then why is a query that will "get me all of the children related to other parents" not what you are looking for?
The only other thing I can see is if you have some children that have a null value in the column(s) that form the foreign key relationship. If that is the case, then you could try the following:
SELECT <desired columns>
FROM my_table
WHERE child_column <> parent_column_value
OR child_column IS NULL;
I may have been confused when I said one to many relationship. (I orignally view it that way because or the parent-child logic being used (the children do not have any meaning on their own).) There are actually three tables here.
1) A list of parents
2) A list of children
3) A join between the two
I want everything in table 2 that has not been joined with parent X in table 3.
If I select everything in table 2 that is not related to parent X, I will get all of the children related to the other parents in table 1.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.