I'm looking to run an UPDATE, and a subsequent DELETE if necessary, query on my table (let's call it MY_TABLE) that would merge all rows in the following way.
Input Table
ID LowerRange UpperRange Attribute
1 10 20 A
2 20 30 A
3 40 50 A
4 15 35 B
Output table
ID LowerRange UpperRange Attribute
1 10 30 A
3 40 50 A
4 15 35 B
Notice how...
- Rows 1 & 2 of the Input Table are merged into Row 1 of the Output Table because their ranges overlap and they have the same Attribute.
- Row 3 of the Input Table is not merged with Rows 1 & 2 because their ranges don't overlap, despite them having the same Attribute.
- Row 4 of the Input Table is not merged with Rows 1 & 2 because they don't have the same Attribute, despite having overlapping ranges.
All rows in TABLE would be merged where their ranges overlap and they have the same Attribute.
Let me know if you have any questions. Any help would be greatly appreciated.
Thanks, Stephen.