Question

I am trying to find whether a set of numbers are contained in another set of numbers.

ID NumberSet Result  
-- --------- ------
1  1457      5741
2  4187      7148
3  6324      1345

So for this dataset I would return ID 1 & 2. All the numbers from the NumberSet must be contained within the Result.

Any suggestions?

Was it helpful?

Solution

This actually isn't that hard. Just look for the reverse . . . is there a case where a number from NumberSet is not in Result?

For the first row, you could manually create a like expression for finding a result that has a character other than "1457":

where Result like '%[^1457]%'

What you want is:

where Result not like '%[^1457]%'

Now, let's generalize:

where Result not like '%[^'+NumberSet+']%'

OTHER TIPS

It seems not easy but you can look into this blog http://wikiprogrammer.wordpress.com/2011/10/17/find-out-anagram-using-sql/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top