简体   繁体   English

如何在mysql数据库中搜索包含字符串中字母的字段

[英]How to search in a mysql database the fields that contains the letters from a string

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'. 例如,如果我输入单词“ steve”,则查询必须查找包含字母“ 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. 请问你能帮帮我吗。

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. 确保您的史蒂夫也小写。

Take a look here MYSQL search for right words | 在这里看看MYSQL搜索正确的单词| fixing spelling errors 修正拼写错误

You can use SOUNDEX or SOUNDS LIKE but that is costly and may not be what you want. 您可以使用SOUNDEXSOUNDS LIKE但这很昂贵,可能不是您想要的。 Maybe you can return all the rows and parse with a levestien(sp) shift if you are using PHP? 如果使用PHP,也许可以返回所有行并使用levestien(sp)移位进行解析?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM