I want to build a mysql query to search comma-separate string with in another comma-separate string.

For example : search string '1,3,5' from '1,2,3,4,5,6'

What will be the mysql query?

1 Year
Discussion Span
Last Post by abhi10kumar

It is going to depend on what type of result you want from the data.
For example: are you wanting it to be selected if the individual elements of the search string are in the data string
If you have a search string '1,3,5' from and llok for each element in '1,2,3,4,5,6' would be true for this search since 1,3,5 and elements in the data string. If this is what you want then you will have to separate out the individual elements and search the data for them. Sub set of this would also need to know if every element has to be present in the data string or if at least 50-60 percent are there.

Or are you looking for the comma separated search sting to exist intact in the data.
search string '1,3,5' from '1,2,3,4,5,6' would not be selected in the data string because 2 is between 1 and 3 in the data but searching for
'1,2,3' would select because the elements are present and in the same order.

Once you lock down all of the parameters and if you aere still puzzled the tell us better what you are looking for.

The sub-string will always be from the original string with different orders (comma separated)
Below are the few example.
Original String : 1,2,3,4,5,6
    a. 1,2,4,6
    b. 4,6,1 
    c. 2,3

Edited by abhi10kumar

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.