0

I need a little help. I want to search in a database the letters that I pass. For example, if I enter the word "steve", the query must look for all the names that contains the letters 'stve'. I tried with:

"SELECT * FROM users WHERE name LIKE 'steve%'  or name like '%steve'  or name like '%steve%'";

But it doesn't do what I want because it looks for the pattern. The same happens with:

"SELECT * FROM users WHERE INSTR(`name`, 'steve') > 0";

Could you help me please.

alex prezmon
  • 95
  • 1
  • 2
  • 9
  • To search for individual letters from the word, you should use regular expression using `RLIKE` – Simon Dec 14 '16 at 00:35

2 Answers2

0

Could it be case problem??How if you use the following query.

"SELECT * FROM users WHERE lower(name) LIKE 'steve%'  or lower(name) like '%steve'  or lower(name) like '%steve%'";

Make sure your steve also lower case.

mokh223
  • 544
  • 3
  • 5
  • 14
0

Take a look here MYSQL search for right words | fixing spelling errors

You can use SOUNDEX or SOUNDS LIKE but that is costly and may not be what you want. Maybe you can return all the rows and parse with a levestien(sp) shift if you are using PHP?

Community
  • 1
  • 1
Ray
  • 773
  • 9
  • 21