MySQL locate function

By | March 1, 2012

So everyone knows sql LIKE to search wildcard matches the criteria. How about in a situation that you need to return all the rows that has value is part of the criteria string.

eg. given a full URL http://www.abc.com/bl/abcdefg/, return all the rows with uri_part field that values are part of the URL string.

Normally LIKE statement works on the other way around, so you need to use LOCATE function. So in this example would be:

Leave a Reply

Your email address will not be published. Required fields are marked *