Jump to content

Substring search with multiple delimiters


smus

Recommended Posts

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

Link to comment
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.

Link to comment
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
×
×
  • Create New...