List:General Discussion« Previous MessageNext Message »
From:Thimble Smith Date:August 4 1999 5:05pm
Subject:Re: LIKE operator
View as plain text  
Jennifer, you're probably familiar with Unix regular expressions (like
you'll find in sed, grep, etc.).  Here's what LIKE is like, in terms
of regexps.

    LIKE "foo"          /^foo$/         (same as = "foo" in SQL)
    LIKE " foo "        /^ foo $/       (same as = " foo ")
    LIKE "%foo"         /foo$"
    LIKE "foo%"         /^foo/
    LIKE "%foo%"        /foo/
    LIKE "% foo %"      / foo /

So, if you don't use any special characters (%, _) in the string after
LIKE, then LIKE behaves the same way = behaves.

I can't think of a good way to handle word boundaries using LIKE (so
that LIKE "%discover%" will match "Discover the world!" but not "I
discovered the world!"  There probably is a good way to do it, but
it's escaping me right now.

Tim

At 12:48, 19990804, toxalot@stripped wrote:
>I'm having trouble understanding how LIKE works.
>
>IF I use 
>$keyword = 'discover';
>SELECT pro_id FROM profiles WHERE profile LIKE "$keyword"
>
>It should match only instances of discover and not discovery, right?
>
>Will it match discover even if the instances of discover has a space on
>each side?
>
>The above gives me no results.
>
>Or do I have to use
>
>SELECT pro_id FROM profiles WHERE profile LIKE "%$keyword%"
>
>I've tried a few different scenarios and I can't seem to get consistent
>results.
>
>IF I try
>
>$keyword = 'discover';
>SELECT pro_id FROM profiles WHERE profile LIKE "%$keyword%"
>
>I get all kinds of matches, but if $keyword = ' discover '; I get 2 matches.
>
>I thought that 
>
>$keyword = ' discover ';
>SELECT pro_id FROM profiles WHERE profile LIKE "%$keyword%"
>
>and 
>
>$keyword = 'discover';
>SELECT pro_id FROM profiles WHERE profile LIKE "$keyword"
>
>would be the same results.
>
>Thanks for your help
>
>Jennifer
Thread
LIKE operatortoxalot4 Aug
  • Re: LIKE operatorThimble Smith4 Aug
    • Re: LIKE operatortoxalot4 Aug
RE: LIKE operatoradhir4 Aug
  • Re: LIKE operatorThimble Smith4 Aug
RE: LIKE operatoradhir4 Aug
  • RE: LIKE operatortoxalot5 Aug
    • Re: LIKE operatorThimble Smith5 Aug
Re: LIKE operatorChristian Mack5 Aug
RE: LIKE operatoradhir5 Aug