I have two tables that look a little like this
AGR_TERR_DEF_TERRS
ID
DEF_ID
TERRITORY_ID (foreign key links to TERRITORIES.ID)
TERRITORIES
ID
NAME
PARENT_ID
(parent_id and id are recursive)
Given two DEF_IDs, I need a function which checks whether the territories of one is a complete subset of the other. I've been playing with CONNECT BY, and INTERSECT, but have written a big mess rather than a useful function.
I'm hoping there will be a (relatively) easy SQL query that works.