Lets say I have a table for a bill of material that looks like the following:
+----------+-------------+
| ParentNo | ComponentNo |
+----------+-------------+
| AAA | 101 |
| AAA | 102 |
| BBB | 201 |
| BBB | 202 |
| CCC | 101 |
| CCC | 201 |
| CCC | 301 |
| DDD | 101 |
| DDD | 102 |
+----------+-------------+
I would like to write a query that find any parent numbers that share identical sets of components. I am flexible on the output, but my initial idea is that it would be similar to:
+----------+---------+
| ParentNo | Matched |
+----------+---------+
| AAA | DDD |
| DDD | AAA |
+----------+---------+
There are multiple ways to find individual records that share the same value for one or multiple fields as discussed in Finding duplicate values in a SQL table. But I only want to return a result when all the components for two different parents match.
The closest solution I have seen to this is SQL selecting rows where one column's value is common across another criteria column. This does not satisfy my need because a set of specific ComponentNo's must be provided. I am trying to avoid manually entering in the ComponentNo's for each individual ParentNo (the datasets that I am working with contain tens of millions of records).
I feel like some form of a recursive query might be appropriate in this situation, but my attempts have not yielded any queries that seem like they are on the right path.