简体   繁体   English

仅使用字符串的一部分进行搜索

[英]Search using only part of the string

Under a column named "name" I have a row which holds the value "Joe". 在名为“名称”的列下,有一行包含值“ Joe”的行。

What can I use so when I search "Joe Bloggs" it will return the row that only holds "Joe"? 我可以使用什么来搜索“ Joe Bloggs”,它将返回仅包含“ Joe”的行?

You could do this: 您可以这样做:

SELECT *
FROM   mytable
WHERE  INSTR(:value, name) > 0

Where :value should be the parameter you will bind to that SQL statement. 其中:value应该是您将绑定到该SQL语句的参数。

You can also use LIKE : 您也可以使用LIKE

select *
from t
where $value like concat('%', name, '%');

If you want the name "Joe" only at the beginning: 如果只想在开头使用“ Joe”这个名字:

select *
from t
where $value like concat(name, '%');

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

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