I have two tables that look a bit 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 the two DEF_IDs, I need a function that checks if the territory of one of them is a complete subset of the other. I played with CONNECT BY and INTERSECT, but wrote a big mess, not a useful feature.
I hope there will be a (relatively) simple SQL query that works.
source
share