Question

I currently have data like this

            ID          range_1   range_2
|3V20.0303:3V20.0313|   |3V20.0303| |3V20.0313|

|3V20.0101:3V20.0108|   |3V20.0101| |3V20.0108|

|3V20.0305:3V20.0308|   |3V20.0305| |3V20.0308|

|3V20.0104:3V20.0104|   |3V20.0104| |3V20.0104|

|3V20.0501:3V20.0505|   |3V20.0501| |3V20.0505|

And i have problem to fine the data which is included in the range1 and range2. it must be something like this

            ID          range_1   range_2
|3V20.0305:3V20.0308|   |3V20.0305| |3V20.0308|

|3V20.0104:3V20.0104|   |3V20.0104| |3V20.0104|

|3V20.0501:3V20.0505|   |3V20.0501| |3V20.0505|

Can any one help me?

I've been trying the code like this and it's all wrong.

SELECT id, range1, range2 
FROM tbl_test
WHERE range1 BETWEEN range1 AND range2 
   or range2 between range1 and range2
Was it helpful?

Solution

Possibly do a self join where the range_1 and range_2 are both between a rows range_1 and range2.

Something like this:-

SELECT a.*
FROM SomeTable a
INNER JOIN SomeTable b
ON a.range_1 BETWEEN b.range_1 AND b.range_2
AND a.range_2 BETWEEN b.range_1 AND b.range_2
AND (a.range_1 != b.range_1
OR a.range_2 != b.range_2)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top