• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 556
  • Last Modified:

SQL "LIKE" question

Running MySQL 5+, Railo CF, Windows 2008 server

I want to search a field in my table for multiple keywords, and my question is what is the best way to handle this?

Here's an example of what I'm trying to do:

SELECT * FROM residential,seo WHERE residential.MLSNum=seo.MLSNum AND publiccomments LIKE '%foreclos%' OR publiccomments LIKE '%bank owned%' OR publiccomments LIKE 'REO' ORDER BY Price DESC

Is there a better way to handle this??

Thanks!
0
Bang-O-Matic
Asked:
Bang-O-Matic
2 Solutions
 
mrh14852Commented:
I don't think there is any better way however you should enclose them all in brackets.

AND (publiccomments LIKE '%foreclos%' OR publiccomments LIKE '%bank owned%' OR publiccomments LIKE 'REO')

Also if the table is very large it will get slow unless you have a full text index which is only supported on a MyISAM table.
0
 
IP512Commented:
the statement is good, i would just make the logical order clear this way:

SELECT * FROM residential,seo WHERE (residential.MLSNum=seo.MLSNum) AND (publiccomments LIKE '%foreclos%' OR publiccomments LIKE '%bank owned%' OR publiccomments LIKE 'REO') ORDER BY Price DESC;

in the last comparison you could also take publiccomments='REO' because there is no wildcard.

if the tables are very big make sure that you have an index on the table holding the field publiccomments, otherwise the query can become slow if the tables are very big.
0
 
Bang-O-MaticAuthor Commented:
Thanks! that's exactly what I needed.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now