I need to find a way to matching the number sequence that I have in one table to a sequence in another table but with different numeric values in SQL if possible.
Example:
Table A contains
Word | Location
-----------------
Quick 2
Brown 3
Fox 4
Table B contains
Word | Location | Product
------------------------------
Quick 2 A
Brown 3 A
Fox 4 A
Brown 8 B
Fox 9 B
Quick 10 B
Quick 7 C
Quick 18 D
Brown 19 D
Fox 20 D
Basically I only want to return Product A & D from table B because they are the only ones who have a reference to all three words and importantly those words are in the same ordered sequence ie 2,3,4 being the same as 18,19,20 only with different numeric values.
It is easy to find out all the products which reference all of the words but I only want products which match all of the same words in the correct order.
Note often the order won’t be as simple as 2,3,4 it could be 2,7,9 and in which case if a product had all of the words with in an order of 36, 41, 43 I would want it returned.
I hope the above makes sense
try this:
SQL fiddle demo