MySQL SELECT查询字符串匹配 [英] MySQL SELECT query string matching

查看:97
本文介绍了MySQL SELECT查询字符串匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常,当使用SELECT查询数据库时,通常希望查找与给定搜索字符串匹配的记录.

Normally, when querying a database with SELECT, its common to want to find the records that match a given search string.

例如:

SELECT * FROM customers WHERE name LIKE '%Bob Smith%';

该查询应该为我提供所有记录,其中"Bob Smith"出现在名称字段中的任何地方.

That query should give me all records where 'Bob Smith' appears anywhere in the name field.

我想做的恰恰相反.

我不是查找名称字段中具有"Bob Smith"的所有记录,而是要查找名称字段位于"Robert Bob Smith III,PhD."(查询的字符串参数)中的所有记录.

Instead of finding all the records that have 'Bob Smith' in the name field, I want to find all the records where the name field is in 'Robert Bob Smith III, PhD.', a string argument to the query.

推荐答案

只需扭转一下

SELECT * FROM customers
WHERE 'Robert Bob Smith III, PhD.' LIKE CONCAT('%',name,'%')

这篇关于MySQL SELECT查询字符串匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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