0

I know that MySQL queries are pretty exact. But I don't want it so exact.

If I have a query of cheeseburger. I want burger to return. Or cheese. Or even cheeseburgers.

Thanks!

Edit: Cheeseburgers is not the only problem. It's for any word. Because I'm trying to build a search system. And I want similar words/ results considered/ returned also.

Michael King
  • 640
  • 1
  • 6
  • 18
  • Is cheeseburgers the only problem or would you like the same thing to apply for words like `housecat` as well? (i.e. find both house and cat). Basically I think your question is not very clear. – Simon Forsberg Mar 10 '13 at 22:39
  • 1
    Cheeseburgers is not the only problem. It's for any word. Because I'm trying to build a search system. And I want similar words/ results considered/ returned also. – Michael King Mar 10 '13 at 23:14
  • 1
    That's what I thought. What you are trying to do is not a simple task I think, but there are solutions out there! – Simon Forsberg Mar 10 '13 at 23:17
  • Do you have any idea on how to do what I need to accomplish? Even if you point me in the right direction that would be great! – Michael King Mar 10 '13 at 23:19

3 Answers3

3

Use LIKE and %:

SELECT id, name FROM mytable WHERE name LIKE '%cheese%' OR name LIKE '%burger%'

Edit:

You might also be searching for How to find similar results and sort by similarity?

Community
  • 1
  • 1
h2ooooooo
  • 39,111
  • 8
  • 68
  • 102
  • Not sure this is what the OP is looking for. Sounds to me like he wants to search for cheeseburger and find both cheese and burger. – Simon Forsberg Mar 10 '13 at 22:37
  • If I were to do, %cheeseburger%, would cheese and burger be returned? Or does it not break down words – Michael King Mar 10 '13 at 23:16
  • 1
    @MichaelKing No, you'd have to use Lucene or another search engine for that (maybe Levensthein, but it's slow on MySQL). Your best bet is to check the link I posted - it explains everything you need (and then you don't have to build your own search system which will be slower than something already built.) – h2ooooooo Mar 10 '13 at 23:21
0

use SOUNDEX:

select * from table where SOUNDEX(name)=SOUNDEX("burger") or  SOUNDEX(name)=SOUNDEX("cheese")
Pierre
  • 34,472
  • 31
  • 113
  • 192
  • 2
    Note, from the manual: `This function, as currently implemented, is intended to work well with strings that are in the **English language only**. Strings in other languages may not produce reliable results.` – h2ooooooo Mar 10 '13 at 22:38
0

Use

%cheese% OR %burger%

This will retun cheese, burger and cheeseburger also anything which has cheese and anything which has burger

technocloud
  • 122
  • 6