I have the following table in DB2 with parent and child ranges. Each row contains the parent and the corresponding minimum and maximum value that its children can have:
parent child_min child_max
------ --------- ----------
1 100 300
2 500 899
...
...
Now, I am trying to find the parents of a set of children in a single query.
Example: I have child ids:
101, 102, 105, 208, 506.
Now the query should return their respective parents
1,1,1,1,2.
I did it by CTE .
WITH temp(id) AS (VALUES
101,102,105,208,506)
SELECT parent FROM table,temp
WHERE child_min < = temp.id
AND child_max >= temp.id
But is there another way to do it without CTE in a single query ?