Is this the correct code for searching multiple fields for a keyword?
SELECT * FROM table WHERE (field1 LIKE "%keyword%" OR field2 LIKE "%keyword%" OR field3 LIKE "%keyword%" OR field4 LIKE "%keyword%");
Thanks, Maynard.
Birdman
1:24 pm on Feb 18, 2004 (gmt 0)
It looks correct to me. I don't wrap the conditionals in parens, but it's probably allowed. If you want exact matched, be sure to put a space before and after the keyword or else you will get stemmed results. (ie. search fro drum will return drummer,drums,etc..)
Woz
1:35 pm on Feb 18, 2004 (gmt 0)
Almost true Birdman. Putting a space around the search terms in the LIKE clause will catch "most" of the exact matches, but don't forget about punctuation! Constructing a true Exact clause is a little more complicated.
Onya Woz
Birdman
2:02 pm on Feb 18, 2004 (gmt 0)
Good call Woz! I guess you would have to cancel stemmed words out after retrieveing the result set.