MYSQL搜索/通配符 [英] MYSQL Search/Wildcards

查看:114
本文介绍了MYSQL搜索/通配符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用PHP搜索MySQL数据库,搜索工作正常,但是我在寻找通配符方面的帮助:

I trying to search a MySQL database using PHP, The search works fine but I'm looking for a little help with wildcards:

我正在搜索的字段(模型)中的数据为:"A4"(215个结果)

The data in the field (Model) I am searching is: "A4" (215 results)

我的搜索字符串是:

SELECT * FROM `temp_comp`.`mvl` WHERE `Model` LIKE '%A4 Avant%'

有没有办法我仍然可以搜索"A4 Avant",但这将返回任何包含"A4"或"Avant"的字段

Is there a way I can still search 'A4 Avant' but this will return any fields that contain 'A4' or 'Avant'

搜索词取自csv文件,因此我想尝试执行此操作而不必先拆分两个单词并搜索"A4"和/或"Avant",但我尝试了以下操作,但未得到结果:

The search term is taken from a csv file so I wanted to try and do this without having to split the two words first and search for 'A4' and/or 'Avant', I have tried the following but get no results:

SELECT * FROM `temp_comp`.`mvl` WHERE `Model` LIKE '%A4%Avant%'

您可能已经猜到这不是我的专业领域,因此,非常感谢您的帮助.

As you may have guessed this is not my normal field so any help would be very much appreciated.

推荐答案

SELECT * FROM temp_comp.mvl WHERE (Model LIKE '%A4%') OR (Model LIKE '%Avant%')

如果要避免拆分测试,可以使用正则表达式:

If you want to avoid splitting up the test you can use a regexp:

SELECT * FROM temp_comp.mvl WHERE Model REGEXP 'A4|Avant'  <<-- Either '%A4% or %Avant%
SELECT * FROM temp_comp.mvl WHERE Model REGEXP 'A4*Avant'  <<-- '%A4%Avant% 

请参见参考

这篇关于MYSQL搜索/通配符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆