That should have been "MATCH (field_name)", not table_name.
Main Topics
Browse All TopicsI'm just doing a simple searching type script and can't seem to find the answer to this anywhere. In MSSQL, I can run the following:
SELECT field_name
FROM table_name
WHERE CONTAINS(field_name, ' this AND that ')
which will return all values of field name that contain the strings 'this' and 'that'. I know I can do the following in MySQL which will give me the same results:
SELECT field_name
FROM table_name
WHERE (field_name like '%this%' AND field_name like '%that%')
which is fine if I'm only searching for a couple of strings but gets ugly quickly as the number goes up.
Is there a MySQL equivalent to the CONTAINS function that I can use? (MySQL version 4.0.21)
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
You might consider a FULLTEXT index and search:
http://dev.mysql.com/doc/r
The specific IN BOOLEAN MODE documentation is here: http://dev.mysql.com/doc/r
If you're not using IN BOOLEAN MODE, what are you using?
I believe that when you use it like that, you are using it in 'analog mode' where each field is scored between 0.0 and 1.0 depending on how well it matches the search terms. When you use '+this +that' IN BOOLEAN MODE, it will only report fields that match the exact rule specified by the text in quotes. When you leave IN BOOLEAN MODE off it uses its fuzzier search algorithm, and will return all results where the score is > 0.5.
To get the fields that score best, you have to do something like this:
SELECT field_name, MATCH(field_name) AGAINST ('this that') AS score
FROM table_name
ORDER BY MATCH(field_name) AGAINST ('this that') DESC LIMIT 20;
The MATCH AGAINST term is in there twice, but it gets optimized out so it only gets executed once.
Business Accounts
Answer for Membership
by: NovaDenizenPosted on 2006-02-01 at 07:47:46ID: 15844265
How about :
WHERE field_name LIKE '%this%' AND field_name LIKE '%that%'
That query will be slow since it will have to look at every single record.
Alternatively, you could add a FULLTEXT index. This has the potential to be much faster (as long as you don't modify the table often)
ALTER TABLE table_name ADD FULLTEXT (field_name);
SELECT field_name from table_name WHERE MATCH (table_name) AGAINST ('+this +that' IN BOOLEAN MODE);