Space character SQL LIKE
If your dialect permits it, use SIMILAR TO, which allows for more flexible matching, including the normal regex quantifiers '?', '*' And '+', with the grouping indicated by '()'
where entry SIMILAR TO 'hello +there'
will match 'hello there'
with any number of spaces between the two words.
I think in MySQL it is
where entry RLIKE 'hello +there'
source to share
http://www.techonthenet.com/sql/like.php
The patterns you can choose are as follows:
% allows you to match any string of any length (including zero length)
_ allows you to match one character
source to share
I just replace the whitespace characters with "%" . Let's say I want to make a LIKE query on a line like this "I want to query this line with LIKE"
@search_string = 'I want to query this string with a LIKE'
@search_string = ("%"+@search_string+"%").tr(" ", "%")
@my_query = MyTable.find(:all, :conditions => ['my_column LIKE ?', @search_string])
first I add '%' to the beginning and end of the line with
("%" + @SEARCH_STRING + "%")
and then replace the rest of the remaining spaces with '%' characters , for example
.tr ("", "%")
source to share
I know this is already late, but I never found a solution for this in relation to the question LIKE
.
There is no way to do what you want in SQL LIKE
. You will need to use REGEXP
it [[:space:]]
inside your expression as well.
So, to find one or more spaces between two words ..
WHERE col REGEXP 'firstword[[:space:]]+secondword'
source to share