SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
-
Jun 10, 2004, 00:17 #1
- Join Date
- Apr 2003
- Location
- daejeon, South Korea
- Posts
- 2,223
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
search result record which has a word exactly the same as the keyWord
Code:Data in myTable (ID) message (1) I am a boy (2) You're a girl (3) He is ambitious (4) They are happy (5) who are you
I have above data in myTable, and I have the following code.
Code:SQL code select ID, message from myTable where message like '%#keyWord#%'
Code:result (1) I am a boy (3) He is ambitious
I like to produce the following target result.
Code:target result (1) I am a boy
-
Jun 10, 2004, 00:59 #2
Try:
Code:SELECT ID, message FROM myTable WHERE message LIKE '% am %'
-
Jun 10, 2004, 06:05 #3
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
itsym, that will find the word only if it has spaces before and after
it will not find these:
(6) Am I really?
(7) That's who I am
and if you then say --Code:where message like '% am %' or message like 'am %' or message like '% am'
(9) That's who I am!
this problem is best solved with a regular expression
-
Jun 10, 2004, 09:00 #4
Hi,
regular expressions with MySQL:
http://dev.mysql.com/doc/mysql/en/Regexp.html
You may use this one:
Code:select ID, message from myTable where message rlike '[[:<:]]keyword[[:>:]]'
[[:]]
[[:>:]]
These markers stand for word boundaries. They match the beginning and end of words, respectively. A word is a sequence of word characters that is not preceded by or followed by word characters. A word character is an alphanumeric character in the alnum class or an underscore (_).Never ascribe to malice,
that which can be explained by incompetence.
Your code should not look unmaintainable, just be that way.
-
Jun 10, 2004, 09:25 #5
- Join Date
- Jul 2002
- Location
- Toronto, Canada
- Posts
- 39,347
- Mentioned
- 63 Post(s)
- Tagged
- 3 Thread(s)
tatsächlich
thanks, kleineme
good answer
Bookmarks