Sign in to follow this  
Followers 0
smus

Substring search with multiple delimiters

3 posts in this topic

I need to create a search in a field where there are several delimiters, such as commas, brackets and slashes.

I used FIND_IN_SET parameter when there was just single commas, but it doesn't find a substring when I add more delimiters as a search rule:

SELECT * FROM field WHERE FIND_IN_SET ($searchquery, searchfield) > 0
SELECT * FROM field WHERE FIND_IN_SET ($searchquery, REPLACE(searchfield, '\', '')) > 0

I've connected the second query to the first using OR

Share this post


Link to post
Share on other sites

Hopefully you don't just put an OR between those 2 queries and try to run that as one query, that won't work.  I'm not sure what you're going for though, but you can verify what you're telling it to search through by just printing that out:

 

SELECT REPLACE(searchfield, '\', '') FROM field

You can verify that what you're telling it to search in is what you expect that to be.  That's going to be a very slow query with a lot of data though, which is one of the reasons why it's not a good idea to try and store multiple values in one field.

Share this post


Link to post
Share on other sites

My first guess would be that the backslash is escaping the closing quote for the string. Try '\\'

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0