I am trying to create a query which will return all rows of a table CLASSES that do not matched with another table named CHILD_CLASSES. These two tables look like this,
The table CLASSES is a self referencing table so the top CLASS does not have a parent_id. The Parent ID row is created from the class_id row. So when I inserted A1 as a sub class to A then its parent ID is 1 because A's class_id is 1. And then A11 is a sub class to A1 as well as A12 so their parent_ids will be 2.
CLASS_ID | PARENT_ID | CLASS_NAME
-----------------------------------
1 | -- | A
2 | 1 | A1
3 | 2 | A11
4 | 2 | A12
I then have another table CHILD_CLASSES which will store the children of each CLASS. Since A is the top Class it will have the children of everything below it, A1, A11, and A12. A1 will only have A11 and A12. It looks like this
ID | PARENT_ID | CLASS_ID
----------------------------
1 | 1 | 2
2 | 1 | 3
3 | 1 | 4
5 | 2 | 3
6 | 2 | 4
This is a little archaic but all I am really looking for is a query that will return to me the rows in the CLASSES table that do not have children for a given CLASS_ID. For example, if I run the query on A1 which is class_id 2, it will return to me rows with the class_ids of 1 because the CLASS A is CLASS that has not been set as a child of A1 in the CHILD_CLASSES table. If I were to run the query on A11 then I would get class_ids 1, 2, and 4 because A1 has no children yet, and so on. Any help would be much appreciated.